需要正确的.htaccess配置

时间:2015-01-25 18:38:44

标签: php apache web-services .htaccess web

我的.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/&amp;我希望此链接打开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>

但问题是我遇到了重定向循环问题。我知道&#34; store&#34;在这里被用于两个不同的目的。一个只是在url&amp;中显示一个指向store.php文件。我想要网址 example.com/store / &amp; example.com/store / 打开store.php&amp; example.com/store/someparameter 到storage.php(工作正常)。

1 个答案:

答案 0 :(得分:0)

你需要修复你的病情。 %{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>