[英]htaccess seo-friendly URL's
I need some help to get friendly URL's on my website. 我需要一些帮助才能在我的网站上获得友好的URL。
These are my links i need to rewrite: 这些是我需要重写的链接:
www.example.com/index.php?page=pagename
www.example.com/index.php?page=profile&id=number
This is my .htaccess. 这是我的.htaccess。 I solved the issue for the first link, however I can't do it for the second one.
我为第一个链接解决了该问题,但是对于第二个链接却无法解决。
I would like to have for the second link: 我想要第二个链接:
www.example.com/profile/name or
www.example.com/profile/id
This is my .htaccess file: 这是我的.htaccess文件:
# for www.example.com/index.php?page=profile&id=number
RewriteCond %{THE_REQUEST} \?page=([^&]+)&id=([0-9]+)
RewriteRule ^ /%1/%2? [L,R=301]
# for www.example.com/index.php?page=page
RewriteCond %{THE_REQUEST} \?page=([^&\ ]+)($|\ )
RewriteRule ^ /%1? [L,R=301]
# rewrites back
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/([0-9]+)$ /index.php?page=$1&id=$2 [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)$ /index.php?page=$1 [L]
The code I submitted above solved my problem. 我上面提交的代码解决了我的问题。
You can use: 您可以使用:
# for www.example.com/index.php?page=profile&id=number
RewriteCond %{QUERY_STRING} page=([^&]+)&id=([0-9]+)
RewriteRule ^ /%1/%2? [L,R=301]
# for www.example.com/index.php?page=page
RewriteCond %{QUERY_STRING} page=([^&]+)
RewriteRule ^ /%1? [L,R=301]
And for rewrites back 并重写
# rewrites back
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
RewriteRule ^([^/]+)/([0-9]+)$ /index.php?page=$1&id=$2 [L]
RewriteRule ^([^/]+)$ /index.php?page=$1 [L]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.