htacess重定向到子文件夹导致过多的http状态301重定向

时间:2016-08-09 21:34:57

标签: .htaccess redirect

我有一个问题,我找不到解决方案。

我的网络根目录中有一个子文件夹,我想将所有网址重定向到此子文件夹而不更改网址。

Ex:domain.com/article123.html - > redirecting-> domain.com/subfolder/article123.html但在地址栏中保留domain.com/artcle123.com

所以我把以下内容放在我的root htaccess中:

RewriteEngine on

RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]
RewriteRule !^subfolder/ /subfolder%{REQUEST_URI} [L,NC]

但是现在当我用http://httpstatus.io测试网址时,我得到以下内容

301 → Error while fetching URL. 11 redirect

在子文件夹中我有另一个htaccess:

RewriteCond %{REQUEST_METHOD} =GET
RewriteCond %{QUERY_STRING} ^$
RewriteCond %{REQUEST_URI} "(.*)index.php"
RewriteRule ^index\.php$ %1 [R=301,L]


RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} ^(.*)\.(php|css|js|gif|jpg|jpeg|png)$ [NC]
RewriteRule ^(.+) - [L]

RewriteCond %{REQUEST_URI} (.*)?/admin/(.*)
RewriteRule ^(.+) - [L]

RewriteCond %{REQUEST_URI} (.*)?/images/(.*)
RewriteRule ^(.+) - [L]

RewriteCond %{REQUEST_URI} (.*)?/templates/(.*)
RewriteRule ^(.+) - [L]

RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.+) - [L]

RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^(.+) - [L]

RewriteCond %{REQUEST_FILENAME} -l
RewriteRule ^(.+) - [L]

##boosted CONTENT
RewriteRule (^[a-z]{2})/(.*/)?info/([A-Za-z0-9_-]+)\.html.* shop_content.php?language=$1&gm_boosted_content=$3&%{QUERY_STRING} [PT,L]
RewriteRule (.*/)?info/([A-Za-z0-9_-]+)\.html.* shop_content.php?gm_boosted_content=$2&%{QUERY_STRING} [PT,L]

##boosted PRODUCTS
RewriteRule (^[a-z]{2})/(.*/)?([A-Za-z0-9_-]+)\.html product_info.php?language=$1&gm_boosted_product=$3&%{QUERY_STRING} [PT,L]
RewriteRule (.*/)?([A-Za-z0-9_-]+)\.html product_info.php?gm_boosted_product=$2&%{QUERY_STRING} [PT,L]

##boosted CATEGORIES
RewriteRule (^[a-z]{2})/(.*/)?([A-Za-z0-9_-]+)/?.* index.php?language=$1&gm_boosted_category=$3&%{QUERY_STRING} [L]
RewriteRule (.*/)?([A-Za-z0-9_-]+)/?.* index.php?gm_boosted_category=$2&%{QUERY_STRING} [L]

我不知道为什么。有人可以帮忙吗?

1 个答案:

答案 0 :(得分:0)

root .htaccess看起来不错,请在subfolder/.htaccess中尝试:

RewriteEngine On

RewriteCond %{REQUEST_METHOD} =GET
RewriteCond %{THE_REQUEST} /index\.php
RewriteCond %{REQUEST_URI} (.*)index\.php
RewriteRule ^index\.php$ %1 [R=301,L,NE]

RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L,NE]

RewriteCond %{REQUEST_FILENAME} ^(.*)\.(php|css|js|gif|jpg|jpeg|png)$ [NC,OR]
RewriteCond %{REQUEST_URI} /(admin|images|templates)/
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]

##boosted CONTENT
RewriteRule (^[a-z]{2})/(.*/)?info/([\w-]+)\.html shop_content.php?language=$1&gm_boosted_content=$3 [QSA,L,NC]

RewriteRule (.*/)?info/([\w-]+)\.html shop_content.php?gm_boosted_content=$2 [QSA,L,NC]

##boosted PRODUCTS
RewriteRule (^[a-z]{2})/(.*/)?([\w-]+)\.html product_info.php?language=$1&gm_boosted_product=$3 [QSA,L,NC]

RewriteRule (.*/)?([\w-]+)\.html product_info.php?gm_boosted_product=$2 [QSA,NC,L]

##boosted CATEGORIES
RewriteRule (^[a-z]{2})/(.*/)?([A-Za-z0-9_-]+)/? index.php?language=$1&gm_boosted_category=$3 [L,QSA,NC]

RewriteRule (.*/)?([\w-]+)/? index.php?gm_boosted_category=$2 [L,QSA,NC]