Using htaccess how to turn this type of URL:
http://www.mysite.com/page.php?slug=hello-world
into this type:
http://www.mysite.com/page/hello-world
And not just this one url but all 开发者_运维知识库urls in the 1st format to the 2nd format.
If the second one is the URL you want people to see, use this:
RewriteRule ^page/(.*)$ /page.php?slug=$1
If it's the other way around:
RewriteRule ^page\.php?slug=(.*)$ /page/$1
EDIT: Also, make sure you have the following in your .htaccess
before ANY RewriteRules:
RewriteEngine On
You may want to refer to here and this
Here is my thought to your solution:
RewriteEngine on
RewriteCond %{QUERY_STRING} ^slug=[^/]+$ [NC]
RewriteRule ^page\.php$ http://www.mysite.com/page/$1? [R=301,L]
精彩评论