繁体   English   中英

.htaccess和php文件出现404错误

[英]404 errors with .htaccess and php files

键入时,我不断收到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]

结合使用MAMP和Chrome,我已多次清除缓存

您可以在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]

测试时,请确保您没有其他任何规则。

所以在熬了几个小时之后,我发现了

在网址末尾添加斜杠

RewriteRule ^(contact/[a-zA-Z0-9]+)$ /$1/ [R=301]

用查询字符串重写规则

RewriteRule ^contact/([a-zA-Z0-9]+)/$ /contact/index.php?status=thanks
RewriteCond %{QUERY_STRING} ^status=([a-zA-Z0-9]+)$
RewriteRule ^index.php$ /contact/%1/? [R=301]

这就是对我有用的

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM