I am wondering how would I change the url from:
single.php?id=1
to:
quote-1
Each submitted data has an id, of course. They can go to the URL, the id of the "quote" to get the quote. How would the URL rewrite look? I've tried to use tools online, but ether they didn't work or I didn't understand how to use it.
Place the following your .htaccess file:
RewriteEngine on
RewriteRule quote-(\d+) single.php?id=$1 [QSA]
mod_rewrite documentation
Related
this is my first time to try .htaccess
this is what i want.
example.com/account/blitzen12 -> example.com/account/index.php?id=10&name=blitzen12
i don't want to include the id in rewriting, is it possible?
Note: id and name which is 10 and blitzen12 is retrive from the database.
so far this is what I've tried but it didn't work.
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^account/(.*)$ ./account/index.php?page=account&id=$1&name=$2 [L,NC]
html code.
blitzen12
can anyone help me with this? Thank you.
The "10" or the id, isn't part of the URL:
example.com/account/blitzen12
So you can't rewrite it into another URL, can't pull it out of thin air. You'll either need to just serve the page without an "id" (and pull it out of the database using the "name") or embed it in the URL without the query string, something like:
example.com/account/10/blitzen12
then you'd be able to rewrite it using:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^account/([0-9]+)/(.*)$ ./account/index.php?page=account&id=$1&name=$2 [L,NC]
I got this url
/localhost/andalucia/productdetails.php?value=20
I want to change it to
/localhost/andalucia/productdetails/20
how do you do this and how will you get the value 20 in the handler page?
should I change the coding or I just add an ht access file?
If it is adding a ht access file what code should be in it?
How if I have more pages like:
/localhost/andalucia/product
/localhost/andalucia/home
/localhost/andalucia/contactus
Will they be affected automatically too?
ok i tried to use
RewriteRule ^productdetails/([0-9]+)$ productdetails.php?value=$1 [L,QSA]
but now the problem is all my pictures is gone in the html and i cant open the other page like
/localhost/andalucia/product
/localhost/andalucia/home
/localhost/andalucia/contactus
i need a htaccess code that can open all of these
/localhost/andalucia/product
/localhost/andalucia/home
/localhost/andalucia/contactus
/localhost/andalucia/productdetails/20
pls helpp someone
With the apache extension mod_rewrite it is really easy to transform your pretty URLs into the URLs needed by your script. This .htaccess example which you place in your web root should get you going:
RewriteEngine On
RewriteRule ^andalucia/productdetails/([0-9]+)$ /andalucia/productdetails.php?value=$1 [L]
This example will only rewrite andalucia/productdetails/NNNN... format URLs, all other URLs won't be affected. If you need to pass other query parameters, like /andalucia/productdetails/20?sort=asc you need to pass the QSA flag (query string append) to the rewrite rule:
RewriteRule ^andalucia/productdetails/([0-9]+)$ /andalucia/productdetails.php?value=$1 [QSA,L]
The L flag will prohibit the evaluation of next rules. Just look up the mod_rewrite documentation for a in-depth discussion!
Consider my domain name is
www.mydomain.com
Consider a page request
www.mydomain.com/user/register
I want to add a custom word after base URL for every request inside mydomain.com.example
www.mydomain.com/customword/
www.mydomain.com/customword/user/register
Can we do this using URL rewriting in htaccess file ?
Actually it should execute 'www.mydomain.com/user/register' internally...but externally the URL should look like www.mydomain.com/customword/user/register.
You could create the directory "register", and put an index file inside it that performs the action.
That's probably the simplest way without url rewriting anyway.
UPDATE (since the question was updated)
In .htaccess:
RewriteEngine On
RewriteRule ^([A-Za-z0-9-.]+)/user/register/?$ user/register.php?customword=$1
register.php will receive a GET request:
//User went to www.mydomain/word/user/register
echo $_GET['customword']; // will return word in this case
Make sure that you have mod_rewrite enabled :)
Yes, you can do it with htaccess
Here is an example which will add a trailing slash with url if it doesnt contain trailing slash
http://enarion.net/web/htaccess/trailing-slash/
edit formatting updated
If you are serving one site from this then the following should work:
Edit your .htaccess file to do a url rewrite
accessing www.yourdomain.com/user/registry will actually server content from www.yourdomain.com/customword/user/registry
RewriteEngine On<br>
RewriteCond %{REQUEST_URI} !^/customword/<br>
RewriteRule ^(.*)$ /customword/$1
You haven't mentioned what kind of site you;re using..eg: PHP, MVC etc as you could do similar thing in there as well.
I send an urlencoded address as a GET parameter called fromurl to my page http://localhost/myapp/admin/login.php:
http://localhost/myapp/admin/login.php?fromurl=%2Fmyapp%2Fadmin%2F
I would like to enable a nicer URL on the form using mod_rewrite which I am quite new to. The nicer URL variant of the example above would have the form:
http://localhost/myapp/admin/login/%2Fmyapp%2Fadmin%2F
I have tried this line in .htaccess which did not work (the URL can not be found):
RewriteRule ^admin/login/(.*)$ admin/login.php?fromurl=$1
I have other mod_rewrite rules working. How should I write the RewriteRule in this case?
Try escaping your slashes:
RewriteRule ^admin\/login\/(.*)$ admin/login.php?fromurl=$1
Additionally, you might need to add a rewritebase (before the rewrite rule) because you aren't accessing this via a dedicated hostname
RewriteBase /myapp/
I am not sure if this is possible, but I have the following URL that I want to make more friendly:
http://www.myurl.com/content.php?id=13089093057550&slug=this-is-a-nice-url
And I want it to look like this:
http://www.myurl.com/this-is-a-nice-url
How do I do this?
You'll need to pass the id to your PHP code in order to display content I believe. For example, look at the Stack Overflow URL for this question: http://stackoverflow.com/questions/6520671/htaccess-rewrite-friendly-urls where it is passing both id and slug. So you can have friendly URLs like:
http://www.myurl.com/13089093057550/this-is-a-nice-url
If you decide to go by my suggestion then here is the code you will need in .htaccess:
Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteRule ^([0-9]*)/(.*)/?$ /content.php?id=$1&slug=$2 [L,QSA]
You can get the slug into the querystring, but without providing the id somewhere it's impossible for Apache to supply it. Hopefully you have a way to get the id out of your database using only the URL slug parameter.
RewriteEngine On
# We don't know the id
RewriteRule (.*)$ /content.php?slug=$1 [L,QSA]