我正在尝试使我的网站中的 url 对用户友好,但似乎服务器根本没有考虑 .htaccess 重写命令。
该项目位于 中,localhost并命名为ecommerce. 我想“转换”这个 url:localhost/ecommerce/product?name=abc 到localhost/ecommerce/product/abc.
这是 .htaccess 文件:
RewriteEngine On
RewriteBase /
## hide .php extension
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L,NC]
## To internally redirect /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_URI}.php [L]
##hide /index
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\index [NC]
RewriteRule ^ %1 [R,L,NC]
##HERE IS THE IMPORTANT PART
RewriteCond %{THE_REQUEST} ^(GET|POST|HEAD)\ /product\.php\?name=([^&]+)
RewriteRule ^ /product/%2/? [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/?product/([^/]+)/?$ /product.php?name=$1 [L]
当我访问localhost/ecommerce/product?name=abcurl 时保持原样,当我访问时localhost/ecommerce/product/abc我得到500 Internal Server Error.
我以为xampp httpd.conf有问题,所以改了
<Directory />
AllowOverride None
Order allow,deny
Allow from all
</Directory>
到
<Directory />
AllowOverride All
Order allow,deny
Allow from all
</Directory>
它仍然不起作用!
从 .htaccess 中删除我隐藏 .php 扩展名的部分也没有任何区别。
青春有我