.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=
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= [L,QSA,NC]
确保您在测试时没有任何其他规则。
所以在熬了几个小时之后我想通了
在 url
的末尾添加斜杠
RewriteRule ^(contact/[a-zA-Z0-9]+)$ // [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]
这对我有用
我在输入时总是收到 404 错误。
localhost/shirt.php?id= 后跟我创建的数组中的数字
RewriteEngine On
RewriteRule ^shirts/$ /shirts/shirts.php
RewriteRule ^shirts/([0-9]+)/$ /shirts/shirt.php?id=
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= [L,QSA,NC]
确保您在测试时没有任何其他规则。
所以在熬了几个小时之后我想通了
在 url
的末尾添加斜杠RewriteRule ^(contact/[a-zA-Z0-9]+)$ // [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]
这对我有用