.htaccess htaccess预定义规则hostagator
在hostagator中,我必须使用一些预定义的htaccess规则,如下所示来设置域的主目录.htaccess htaccess预定义规则hostagator,.htaccess,mod-rewrite,.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} !^/su
#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/的URL,我喜欢它是example.com/some_dir/* 但我不能改变以上任何预定义的规则,否则它会破坏我的网站,因为它必须为我的目录结构。因此,添加轨迹斜杠规则也不起作用 我的目录结构如下: / /subdir/.htaccess /subdir/index.php /子目录/某些目录 /子目录/一些其他目录 等
或者以任何其他方式将新请求的example.com/some_dir完全重定向到example.com/some_dir/,以便在新请求后遵循上述规则
部分解决: 我在stackoverflow上找到了添加尾部反斜杠的地方: 重写规则^([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的问题与我的主要问题相同,我如何修改上述规则?那么,你的问题是什么?尽量清晰,并添加一些示例。必须有一些
模式才能提供有用的答案。这里的问题是,当我在浏览器中键入example.com/some_dir(不带尾随斜杠)时,它将显示example.com/subdir/some_dir/之类的URL,我希望它与example.com/some_dir/类似,您所要做的就是删除文件末尾的重写规则。请注意,以这种方式修改URL映射可能会影响性能或产生大量404错误。不,这不会起作用,并且会导致大量404错误,因为正如我所说的,我的站点必须工作。然后,在较低的子目录中修改这些规则的任何规则,将优先于他们,结果将是一样的:问题。尝试要求Hostgator修改这些规则并向他们解释问题。