繁体   English   中英

带有mod_rewrite的友好网址

[英]Friendly url with mod_rewrite

我有这样的网址

http://localhost/rilo/listing.php?id=2

其中“ rilo”是根,我想获得友好的网址,例如

http_//localhost/rilo/listing/2.html

这是htaccess

Options +FollowSymLinks -MultiViews

# Turn mod_rewrite on
RewriteEngine On
RewriteBase /rilo

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/?listing/([a-zA-Z_]+).html$ listing.php?id=$1 [QSA,L]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s(.*)/index\.php [NC]
RewriteRule ^ /%1 [R=301,L]

RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

你能帮助我吗? 错误在哪里?

用以下代码替换代码:

Options +FollowSymLinks -MultiViews

# Turn mod_rewrite on
RewriteEngine On
RewriteBase /rilo

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/?listing/([^.]+)\.html$ listing.php?id=$1 [QSA,L,NC]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s(.*)/index\.php [NC]
RewriteRule ^ %1 [R=301,L]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+[^/]+/(listing)\.php\?id=([^&\s]+) [NC]
RewriteRule ^ %1/%2.html? [R=301,L]

RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM