子文件夹.htaccess重定向到根文件夹

时间:2015-07-17 00:01:36

标签: php apache .htaccess mod-rewrite redirect

这是我的根文件夹.htaccess

Options +FollowSymLinks
Options -Indexes

<IfModule mod_rewrite.c>

RewriteEngine On

RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.domain.net/$1 [R=301,L]

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

</IfModule>

这是我的子文件夹.htaccess

<IfModule mod_rewrite.c>
RewriteCond %{REQUEST_URI} /admin/?$
RewriteRule ^(.*)$ %1/Admin/index.php [NE,R,L]
RewriteCond %{REQUEST_URI} /Admin/?$
RewriteRule ^(.*)$ %1/Admin/index.php [NE,R,L]

RewriteCond %{REQUEST_URI} /stores/?$
RewriteRule ^(.*)$ %1/Stores/ [NE,R,L]

RewriteCond %{REQUEST_URI} /categories/?$
RewriteRule ^(.*)$ %1/Categories/ [NE,R,L]

# working with client side
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]*)$ index.php?qstr=$1 [QSA,L]
RewriteRule ^coupons/(.*)$ index.php?qstr=coupons/$1 [QSA,L]
RewriteRule ^(.*)/$ index.php?qstr=$1 [QSA,L]

</IfModule>

我的问题是,当我尝试访问

http://domain.net/coupon-website/admin

我被重定向到

https://www.domain.net/Admin/index.php

而不是

https://www.domain.net/coupon-website/Admin/index.php

我错过了什么?为什么我被重定向到根文件夹而不是coupon-website子文件夹?

1 个答案:

答案 0 :(得分:0)

经过反复试验,我终于找到了解决方案。 现在这里是我的新子文件夹.htaccess,现在正在按预期工作。

<IfModule mod_rewrite.c>

RewriteCond %{REQUEST_URI} /admin/?$
RewriteRule ^(.*)$ %1/coupon-website/Admin/index.php [NE,R,L]
RewriteCond %{REQUEST_URI} /Admin/?$
RewriteRule ^(.*)$ %1/coupon-website/Admin/index.php [NE,R,L]

RewriteCond %{REQUEST_URI} /stores/?$
RewriteRule ^(.*)$ %1/coupon-website/Stores/ [NE,R,L]

RewriteCond %{REQUEST_URI} /categories/?$
RewriteRule ^(.*)$ %1/coupon-website/Categories/ [NE,R,L]

# working with client side
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]*)$ index.php?qstr=$1 [QSA,L]
RewriteRule ^coupons/(.*)$ index.php?qstr=coupons/$1 [QSA,L]
RewriteRule ^(.*)/$ index.php?qstr=$1 [QSA,L]

</IfModule>