Php 带有mod_重写的友好url

Php 带有mod_重写的友好url,php,mod-rewrite,url-rewriting,friendly-url,Php,Mod Rewrite,Url Rewriting,Friendly Url,我有一个像这样的URL http://localhost/rilo/listing.php?id=2 其中“rilo”是根,我希望得到友好的URL,如 http_//localhost/rilo/listing/2.html 这是htaccess Options +FollowSymLinks -MultiViews # Turn mod_rewrite on RewriteEngine On RewriteBase /rilo RewriteCond %{REQUEST_FILENAM

我有一个像这样的URL

http://localhost/rilo/listing.php?id=2
其中“rilo”是根,我希望得到友好的URL,如

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]

你还没有告诉我们你想要发生什么/发生了什么。对不起,奥利弗,我已经编辑了我的请求。这个答案帮助你解决了你的问题,请考虑把它标记为“被接受”,所以将来面对类似问题的用户将能够很容易地看到它。