开发者

How to rewrite urls using htaccess?

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] 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜