.htaccess和php文件出现404错误

时间:2015-01-15 07:42:12

标签: php .htaccess mamp server

我打字时遇到404错误。

localhost / shirt.php?id =后跟我创建的数组中的数字

RewriteEngine On
RewriteRule ^shirts/$ /shirts/shirts.php
RewriteRule ^shirts/([0-9]+)/$ /shirts/shirt.php?id=$1
RewriteRule ^receipt.php$ /receipt/ [R=301]
RewriteRule ^contact.php$ /contact/ [R=301]
RewriteRule ^shirts.php$ /shirts/ [R=301]

RewriteCond %{QUERY_STRING} ^id=([0-9]+)$
RewriteRule ^shirt.php$ /shirt/%1/? [R=301]

在Chrome上使用MAMP,我已多次清除缓存

1 个答案:

答案 0 :(得分:1)

您可以在DOCUMENT_ROOT/.htaccess文件中使用此代码:

Options -MultiViews
RewriteEngine On
RewriteBase /

# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} \s/+shirt\.php\?id=([^\s&]+) [NC]
RewriteRule ^ shirt/%1? [R=302,L,NE]

# internal forward from pretty URL to actual one
RewriteRule ^shirt/(\d+)/?$ shirt.php?q=$1 [L,QSA,NC]

确保在测试时没有任何其他规则。