使用Mod_rewrite重写文件夹位置时遇到问题

时间:2014-09-18 12:54:09

标签: apache .htaccess mod-rewrite url-rewriting rewrite

我的.htaccess文件中有以下代码,这一切都正常。

RewriteEngine On

RewriteCond %{REQUEST_URI} ^(.*)//(.*)$
RewriteRule . %1/%2 [R=301,L]

RewriteRule ^(.*),(.*)$ $2.php?rewrite_params=$1&page_url=$2

RewriteCond %{QUERY_STRING} base64_encode.*(.*) [OR] 
RewriteCond %{QUERY_STRING} (<|%3C).*script.*(>|%3E) [NC,OR] 
RewriteCond %{QUERY_STRING} GLOBALS(=|[|%[0-9A-Z]{0,2}) [OR] 
RewriteCond %{QUERY_STRING} _REQUEST(=|[|%[0-9A-Z]{0,2}) 
RewriteRule ^(.*)$ index.php [F,L]

RewriteRule ^stores/([0-9a-z.-]+)/?$ shop.php?shop_id=$1 [L,QSA,NC]
RewriteRule ^stores/([0-9a-z.-]+)/ajax_files/watch_item\.php$ ajax_files/watch_item.php [L,QSA,NC]
RewriteRule ^stores/([0-9a-z.-]+)/ajax_files/save_field\.php$ ajax_files/save_field.php [L,QSA,NC]
RewriteRule ^stores/([0-9a-z.-]+)/images/form-cb-icons\.png$ images/form-cb-icons.png [L,NC]

RewriteRule ^group-break/([0-9]+)/[0-9a-z.-]+/?$ group_break.php?cb_id=$1 [L,NC]
RewriteRule ^group-breaks/([a-z]+)-[a-z-]+/?$ group_breaks.php?tab=$1 [L,NC]

但是我试图在底部添加一条新规则:

RewriteRule ^billing/client/login/?$ login.php [L,NC]

然而,这似乎不起作用。不确定它是否重要但是billing目录还有一个.htaccess文件,可能会覆盖它?该文件的内容如下:

<Files ~ "\.(pdt)$">
   order deny,allow
   deny from all
</Files>

# Protect against Clickjacking
#Header append X-Frame-Options "SAMEORIGIN"

RewriteEngine on

# Force HTTPS
#RewriteCond %{HTTPS} !=on
#RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=307,NE,L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php

RewriteCond %{REQUEST_URI} ^(.*)/install.php$
RewriteRule install.php %1/install/ [R=301,L]

我想将我的代码放在根.htaccess文件中,因为billing目录中的代码可用于其他可能被覆盖的软件。

可以这样做吗?

1 个答案:

答案 0 :(得分:1)

是的,你的猜测是正确的。如果/billing/.htaccess存在一些重写规则,那么您需要在/billing/.htaccess文件中添加此规则:

<Files ~ "\.(pdt)$">
   order deny,allow
   deny from all
</Files>

# Protect against Clickjacking
#Header append X-Frame-Options "SAMEORIGIN"

RewriteEngine on

# Force HTTPS
#RewriteCond %{HTTPS} !=on
#RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=307,NE,L]

RewriteCond %{REQUEST_URI} ^(.*)/install.php$
RewriteRule install.php %1/install/ [R=301,L]

RewriteRule ^client/login/?$ /login.php [L,NC]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [L]