【发布时间】:2011-10-19 16:36:52
【问题描述】:
我使用的主机只允许 PHP 文件位于名为 /cgi/ 的子目录中
但现在我所有的链接都是/cgi/..
请原谅我的愚蠢,但我可以在我的 .htaccess 文件中重写,以使网站认为 /cgi/ 是根目录,以便我的所有链接和网站本身似乎都在根目录中?
这是我所拥有的,但它会导致 500 错误:
# Turn on rewrites.
RewriteEngine on
# Only apply to URLs on this domain
RewriteCond %{HTTP_HOST} ^(www.)?thegrancenturions.com$
# Only apply to URLs that aren't already under folder.
RewriteCond %{REQUEST_URI} !^/cgi/
# Don't apply to URLs that go to existing files or folders.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Rewrite all those to insert /folder.
RewriteRule ^(.*)$ /cgi/$1
# Also redirect the root folder.
RewriteCond %{HTTP_HOST} ^(www.)?thegrancenturions.com$
RewriteRule ^(/)?$ cgi/index.php [L]
【问题讨论】:
-
您的主机是否允许重写?如果他们让您将 PHP 放入
/cgi/,如果他们让您在.htaccess中覆盖很多内容,我会感到惊讶... -
是的,他们说他们会将 HTML 文件放在根目录中并重定向它..