我想修改detail.php?Id =4到detail/4,但我的.htaccess文件不工作


I want to change detail.php?id=4 to detail/4,but my .htaccess file not working

这是我的。htaccess文件的样子

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-s
RewriteRule ^home$ index.php [NC,L]
RewriteRule ^detail$ detail.php [NC,L]
RewriteRule ^detail/([0-9a-zA-Z]+)$ detail.php?id=$1 [NC,L]

你说的是使用。htaccess在内部重写你的url,并将它们适当地路由到你的应用程序。

你应该尝试使用这个特定的。htaccess示例,它将做你正在寻找的:

    RewriteEngine On
    # external redirect from actual URL to pretty one
    RewriteCond %{THE_REQUEST} /detail(?:'.php)?'?id=([^'s&]+) [NC]
    RewriteRule ^ detail/%1? [R=302,L,NE]
    # internal forward from pretty URL to actual one
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^detail/([^/]+)/?$ detail.php?id=$1

编辑:

您在htaccess中做的恰恰相反,将detail/4重定向到detail.php?id=4。在你的问题中你说?id=4 to/4

那么交换,编辑和测试