.htaccess - 通过从链接中删除文件夹来重定向页面上的链接
我按照本教程进行管理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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
感谢一些帮助,我设法找到了这个问题的解决方案。
关键行是
RewriteCond %{REQUEST_URI} !^/
。一旦到位,一切都变得容易访问。感谢所有发表评论的人。Thanks to some assistance, I managed to find the solution to this issue.
The key line is
RewriteCond %{REQUEST_URI} !^/
. Once that was in place everything becomes accessible. Thanks to everyone who commented.