我正在尝试使用 htaccess 文件执行简单的重写规则。我使用 XAMPP 在本地主机上托管此页面:
localhost/naveesh/services.php
请求此操作的可能方法如下:
localhost/naveesh/services?serv=Boat%20Dealers
我想做的是将以下 URL 的请求重写为上述 URL
localhost/naveesh/services/Boat-Dealers
我尝试了这个,但它给了我一个 404 错误。
RewriteEngine On RewriteRule ^/naveesh/services/([^/]+)/?$ /naveesh/services.php?serv=$1 [L,QSA]
经过一番研究,我尝试了另一种选择:
RewriteEngine On
RewriteBase /naveesh/
# Hide .php extension
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ $1.php [L]
RewriteRule ^services/([^/]+)/?$ /services.php?serv=$1 [L,QSA]
但是,现在出现了太多内部重定向问题
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号