我可以使用 .htaccess 文件执行此操作吗?
我使用的主机只允许 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]
I'm using a host that will only allow PHP files to be located in a subdir called /cgi/
But now all my links are /cgi/..
Excuse my daftness, but can I write a rewrite in my .htaccess file to make the site think that /cgi/
is the root so that all my links and the site itself appears to be in the root?
This is what I have but its causing a 500 error :
# 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]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我还没有测试过,但类似的东西应该可以工作。您可能还需要添加一个
RewriteCond
来检查传入请求是否不是针对/cgi/..
I've not tested it, but something similar to this ought to work. You may also need to add a
RewriteCond
which checks that incoming requests are not for/cgi/..