我有以下几行在我的.htaccess文件中完美运行。
ErrorDocument 413 error.php?413
ErrorDocument 414 error.php?414
ErrorDocument 500 error.php?500
<IfModule mod_rewrite.c>
Options +FollowSymLinks -MultiViews -Indexes
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}'.php !-f
RewriteRule ^store/([^/'.]+)/?$ storage.php?taid=$1 [L]
RewriteRule ^cart/([^/'.]+)/?$ cart.php?tbid=$1 [L]
</IfModule>
现在,我已经建立了指向例如此 url 的链接http://example.com/store/和我希望这个链接打开store.php
文件。为此,我制作了新代码,即
ErrorDocument 413 error.php?413
ErrorDocument 414 error.php?414
ErrorDocument 500 error.php?500
<IfModule mod_rewrite.c>
Options +FollowSymLinks -MultiViews -Indexes
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}'.php !-f
RewriteRule ^(.*)$ $1.php
RewriteRule ^store/([^/'.]+)/?$ storage.php?taid=$1 [L]
RewriteRule ^cart/([^/'.]+)/?$ cart.php?tbid=$1 [L]
</IfModule>
但问题是我遇到了重定向循环问题。我知道"商店"在这里用于两种不同的目的。一个仅用于显示在 URL 中,另一个用于指向存储.php文件。我希望url的 example.com/store/ 和 example.com/store/ 打开商店.php example.com/store/someparameter 存储.php(工作正常)。
您需要修复您的状况。 %{REQUEST_FILENAME}
和-f
检查是错误的。你想要:
ErrorDocument 413 error.php?413
ErrorDocument 414 error.php?414
ErrorDocument 500 error.php?500
<IfModule mod_rewrite.c>
Options +FollowSymLinks -MultiViews -Indexes
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1'.php -f
RewriteRule ^(.*)$ $1.php [L]
RewriteRule ^store/([^/'.]+)/?$ storage.php?taid=$1 [L]
RewriteRule ^cart/([^/'.]+)/?$ cart.php?tbid=$1 [L]
</IfModule>