htaccess预定义规则hostgator

时间:2012-12-12 05:14:37

标签: .htaccess mod-rewrite

在hostagator中,我必须使用一些预定义的htaccess规则,如下所示设置域的主目录。

#Change example.com to be your main domain.
RewriteCond %{HTTP_HOST} ^(www.)?example.com$*

#Change 'subdirectory' to be the directory you will use for your main domain.
RewriteCond %{REQUEST_URI} !^/subdir/*

#Don't change these line.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d*

#Change 'subdirectory' to be the directory you will use for your main domain.
RewriteRule ^(.*)$ /subdir/$1*

现在问题是当我输入我的浏览器时: example.com/some_dir(没有尾部斜杠) 它会显示像example.com/subdir/some_dir/这样的网址,我喜欢这个网址是example.com/some_dir/*

但是我无法更改任何上述预定义规则,否则会破坏我的网站,因为它必须具有我的目录结构。所以添加traling斜杠规则也不起作用。

我的目录结构是这样的:

/

/subdir/.htaccess

/subdir/index.php

/ subdir / some_dir

/子目录/ some_other_dir


或者将example.com/some_dir完全重定向到example.com/some_dir/以获取新请求的任何其他方式,以便在新请求之后遵循上述规则。?


部分解决:

我在stackoverflow上找到了一个用于添加尾部反斜杠的地方:     RewriteRule ^(([a-z0-9 - ] + /)* [a-z0-9 - ] +)$ $ 1 /

所以只是通过使用我尝试制定这样的规则,然后放在我的上述预定规则之前:

RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteCond %{REQUEST_URI} !^/subdir/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^(.*)/$
RewriteRule ^(([a-z0-9\-]+/)*[a-z0-9\-]+)$ $1/

现在它的工作没有尾随斜线 例如 example.com/some_dir,不会重定向到example.com/subdir/some_dir/,而只是停留在example.com/some_dir(没有斜杠)...

任何人都可以解释这个正则表达式(([a-z0-9 - ] + /)* [a-z0-9 - ] +)是什么意思?它是如何工作的?

现在example.com/some_dir/dir1遇到与我的主要问题相同的问题,我如何修改上述规则?

0 个答案:

没有答案
相关问题