.htaccess 重定向到子文件夹,而不会导致 ajax JS 调用 BE 目录时出错
我需要帮助来设置 100% 工作的 .htaccess ,我在 Google 上搜索了很多,得到了一些建议,部分工作的建议,但仍然不是 100%。 “问题”非常简单:该网站托管在: public_html/
目录,但我的网站位于 /public_html/a/b/FE/
,而后台 -结束于:public_html/a/b/BE/
(其PHP),在内部我使用相对路径(require('../BE/something.php'))。所以我想要一个从 public_html/
到 public_html/a/b/FE/
的完整工作路径重定向。
最“有效”的 .htaccess 是:
RewriteEngine On
Options +FollowSymlinks
RewriteBase /
# handle domain root and skip subfolders
RewriteCond %{HTTP_HOST} www.site.com
RewriteCond %{REQUEST_URI} !^/a/b/FE
RewriteCond %{REQUEST_URI} \..+$
RewriteRule ^(.*)$ a/b/FE/$1 [L]
# add trailing slash to subfolders (eg abc to: abc/)
RewriteCond %{HTTP_HOST} www.site.com
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} [^/]$
RewriteRule ^(.*)$ $1/ [L,R=301]
# handle files in subfolders
RewriteCond %{HTTP_HOST} www.site.com
RewriteCond %{REQUEST_URI} !^/a/b/FE
RewriteRule ^(.*)$ a/b/FE/$1/ [L]
它加载网站,但例如我在 /public_html/a/b/BE/captcha.php 有一个 captcha.php ,它生成一个图像,但找不到该文件。我将其用作:
<img src="../BE/captcha.php" />
此外,在位于 FE 目录中的 JS 中,我对某些后端模块进行 AJAX 调用,其相对位置为: '../BE/some_module.php' 。这也会导致错误,
谢谢!
I need help with setting up 100% working .htaccess , I Googled a lot, came to several suggestions, part-working ones but still not 100%. The "problem" is quite simple: the site is hosted at: public_html/
dir, but my site is in /public_html/a/b/FE/
and the back-end at: public_html/a/b/BE/
(its PHP), inside i use relative path (require ('../BE/something.php')). So i want a fully working path redirect from public_html/
to public_html/a/b/FE/
.
The .htaccess that "worked" the most is:
RewriteEngine On
Options +FollowSymlinks
RewriteBase /
# handle domain root and skip subfolders
RewriteCond %{HTTP_HOST} www.site.com
RewriteCond %{REQUEST_URI} !^/a/b/FE
RewriteCond %{REQUEST_URI} \..+$
RewriteRule ^(.*)$ a/b/FE/$1 [L]
# add trailing slash to subfolders (eg abc to: abc/)
RewriteCond %{HTTP_HOST} www.site.com
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} [^/]$
RewriteRule ^(.*)$ $1/ [L,R=301]
# handle files in subfolders
RewriteCond %{HTTP_HOST} www.site.com
RewriteCond %{REQUEST_URI} !^/a/b/FE
RewriteRule ^(.*)$ a/b/FE/$1/ [L]
It loads the site, but for example i have a captcha.php at /public_html/a/b/BE/captcha.php which generates an image and it cant find the file. I use it as:
<img src="../BE/captcha.php" />
also, in the JS that sits in the FE dir, i call AJAX calls to some back end modules, with their relative location: '../BE/some_module.php' . This causes error as well
thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论