简体   繁体   中英

need correct .htaccess configuration

I've got the following lines that works perfectly in my .htaccess file.

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>

Now, I have already built links that point for eg this url http://example.com/store/ & I want this link to open store.php file. For that I made the new code, which is this

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>

But the problem is I'm getting a redirect loop problem. I know "store" is being used for 2 different purposes here. one for just showing as in url & one as to point to store.php file. I want url's example.com/store/ & example.com/store/ to open store.php & example.com/store/someparameter to storage.php (which works fine).

You need to fix your condition. %{REQUEST_FILENAME} and the -f check is wrong. You want:

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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