.htaccess - 通过从链接中删除文件夹来重定向页面上的链接

发布于 2024-11-27 23:16:24 字数 1127 浏览 2 评论 0原文

我按照本教程进行管理MODx Revo 2.1.3 安装的子域。这个想法是,Web 根文件夹中的 htaccess 文件将对 subdomain.mydomain.com 的调用重定向到 Web 根目录中与子域同名的文件夹,即 /home/mydomain/www/subdomain。子域包含运行页面的 MODx 文件,以及另一个将所有进一步请求指向根文件夹的 htaccess。

它的更好的部分是有效的;我可以查看该网站的主页(这意味着 MODx 正在尽其所能),但是 css、js、图像等的链接都不起作用,而且 Wayfinder 和 getResources 包似乎无法输出。用于图像+css+js 的链接是/subdomain/assets...等;我需要链接直接指向 /assets 文件夹。这就像根 .htaccess 可以将请求重定向到子域文件夹,但文件夹中的 .htaccess 不会将任何内容指向剩余请求的根。

这是我的根文件夹 htaccess,取自教程的第二部分:

RewriteEngine On
RewriteBase /

# The Multiple subdomains part
#REDIRECT SUBDOMAIN TO SUBDIRECTORY OF SAME NAME
RewriteCond %{ENV:REDIRECT_SUBDOMAIN} =""
RewriteCond %{HTTP_HOST} ([a-z0-9][-a-z0-9]+)\.mydomain\.com\.?(:80)?$ [NC]
RewriteCond %{DOCUMENT_ROOT}/%1 -d
RewriteRule ^(.*) %1/$1 [E=SUBDOMAIN:%1,L]
RewriteRule ^ - [E=SUBDOMAIN:%{ENV:REDIRECT_SUBDOMAIN},L]

子域文件夹 htaccess 很简单:

RewriteEngine On
RewriteBase /

我知道该网站可以工作;我可以使用尚未像教程一样处理的子域来访问它。所以一切都在那里,我只需要整理链接请求即可。有人可以帮忙吗?

I followed this tutorial to manage subdomains for a MODx Revo 2.1.3 installation. The idea is that the htaccess file in the web root folder redirects calls for subdomain.mydomain.com to a folder in the web root directory by the same name as the subdomain, ie /home/mydomain/www/subdomain. Subdomain contains the MODx files to run the page, as well as another htaccess to point all further requests back to the root folder.

The better part of it works; I can view the homepage of the site (which means MODx is doing its part), but none of the links to the css, js, images, etc work, and it seems like the Wayfinder and getResources packages are failing to output. The links that are being used for the images+css+js are /subdomain/assets...etc; I need the links to point directly to the /assets folder. It's like the root .htaccess works to redirect the request to the subdomain folder, but the .htaccess in the folder doesn't point anything back up to the root for the remaining requests.

Here's my root folder htaccess, the 2nd part taken from the tutorial:

RewriteEngine On
RewriteBase /

# The Multiple subdomains part
#REDIRECT SUBDOMAIN TO SUBDIRECTORY OF SAME NAME
RewriteCond %{ENV:REDIRECT_SUBDOMAIN} =""
RewriteCond %{HTTP_HOST} ([a-z0-9][-a-z0-9]+)\.mydomain\.com\.?(:80)?$ [NC]
RewriteCond %{DOCUMENT_ROOT}/%1 -d
RewriteRule ^(.*) %1/$1 [E=SUBDOMAIN:%1,L]
RewriteRule ^ - [E=SUBDOMAIN:%{ENV:REDIRECT_SUBDOMAIN},L]

and the subdomain folder htaccess is simply:

RewriteEngine On
RewriteBase /

I know the site works; I can access it using a subdomain that hasn't been processed like the tutorial yet. So it's all there, I just need to sort out the link requests. Can anyone help?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

固执像三岁 2024-12-04 23:16:24

感谢一些帮助,我设法找到了这个问题的解决方案。

# The Multiple subdomains part
#REDIRECT SUBDOMAIN TO SUBDIRECTORY OF SAME NAME
RewriteCond %{ENV:REDIRECT_SUBDOMAIN} =""
RewriteCond %{HTTP_HOST} ([a-z0-9][-a-z0-9]+)\.spitfireresources\.com\.?(:80)?$ [NC]
RewriteCond %{DOCUMENT_ROOT}/%1 -d
#RewriteCond %{REQUEST_FILENAME} !^/js
#RewriteCond %{REQUEST_FILENAME} !^/css
#RewriteCond %{REQUEST_URI} !^/assets
RewriteCond %{REQUEST_URI} !^/
RewriteRule ^(.*) %1/$1 [E=SUBDOMAIN:%1,L]
RewriteRule ^ - [E=SUBDOMAIN:%{ENV:REDIRECT_SUBDOMAIN},L]

关键行是 RewriteCond %{REQUEST_URI} !^/。一旦到位,一切都变得容易访问。感谢所有发表评论的人。

Thanks to some assistance, I managed to find the solution to this issue.

# The Multiple subdomains part
#REDIRECT SUBDOMAIN TO SUBDIRECTORY OF SAME NAME
RewriteCond %{ENV:REDIRECT_SUBDOMAIN} =""
RewriteCond %{HTTP_HOST} ([a-z0-9][-a-z0-9]+)\.spitfireresources\.com\.?(:80)?$ [NC]
RewriteCond %{DOCUMENT_ROOT}/%1 -d
#RewriteCond %{REQUEST_FILENAME} !^/js
#RewriteCond %{REQUEST_FILENAME} !^/css
#RewriteCond %{REQUEST_URI} !^/assets
RewriteCond %{REQUEST_URI} !^/
RewriteRule ^(.*) %1/$1 [E=SUBDOMAIN:%1,L]
RewriteRule ^ - [E=SUBDOMAIN:%{ENV:REDIRECT_SUBDOMAIN},L]

The key line is RewriteCond %{REQUEST_URI} !^/. Once that was in place everything becomes accessible. Thanks to everyone who commented.

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