我可以使用 .htaccess 文件执行此操作吗?

发布于 2024-12-11 03:12:52 字数 790 浏览 0 评论 0原文

我使用的主机只允许 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

深陷 2024-12-18 03:12:52
RewriteEngine On
RewriteRule ^(.+?)$ cgi/$1 [QSA,L]

我还没有测试过,但类似的东西应该可以工作。您可能还需要添加一个 RewriteCond 来检查传入请求是否不是针对 /cgi/..

RewriteEngine On
RewriteRule ^(.+?)$ cgi/$1 [QSA,L]

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/..

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文