htaccess 重写错误

发布于 2024-09-24 23:31:47 字数 934 浏览 2 评论 0原文

我在 godaddy 托管的两个 htaccess 文件有问题。我在同一主机中有多个域,因此我使用了我发现的 htaccess,它运行得很好:

RewriteEngine On
RewriteBase /

# To redirect www.site1.com to /site1/
RewriteCond %{REQUEST_URI} !^/site1/
RewriteCond %{HTTP_HOST} ^(www\.)?site1\.www\.
RewriteRule ^(.*)$ site1/$1 [L]

这很棒,因为它将访问 site1.com 的人重定向到 /site1/,并且我在该目录中有 site1 的页面。事实上,我有同样的三个其他域,它们工作得很好(该文件夹隐藏在网址栏中)。

我的问题是我添加了一个新域 (site2.com),即 Zend 应用程序。因此它有自己的 htaccess 用于重写 url(用于在 url 中以更好的方式传递参数)。对于这个来说,它不起作用。事实上,我被重定向回 / 并且我得到了一个页面 /index.html ,没有人应该能够获得该页面。请注意:zend 应用程序的 webroot 是“www”:

第二个 htacess,位于 /site2/www 内,

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]

我不知道它是如何返回的。 htaccess 命令路径不是相对的吗?为什么它会返回两个级别(请记住它位于 /site2/www 中,而我得到的文件位于 /index.php (测试))

I have a problem with two htaccess files that i have in a hosting at godaddy. I have multiple domains in the same hosting and therefore i usen htaccess which i found and which is working great:

RewriteEngine On
RewriteBase /

# To redirect www.site1.com to /site1/
RewriteCond %{REQUEST_URI} !^/site1/
RewriteCond %{HTTP_HOST} ^(www\.)?site1\.www\.
RewriteRule ^(.*)$ site1/$1 [L]

This is great because it redirects whoever goes to site1.com to /site1/ and i have the page for site1 in that directory. In fact i have this same three others domains and they work great (the folder is hidden in the url bar).

My problem is that i added a new domain (site2.com) which is Zend app. Therefore it has it's own htaccess for rewriting the url (for passing parameters in a nicer way in the url). For this one it doesnt works. In fact i am redirected BACK to / and i get a page /index.html which nobody is supposed to be able to get. Just to notice: the zend app's webroot is 'www':

The second htacess, inside /site2/www is

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]

I don't know how is it going back. Aren't htaccess commands path relative ? why is it going back two levels (remember that it is in /site2/www and the file i'm getting is at /index.php (a test))

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

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

发布评论

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

评论(1

╰つ倒转 2024-10-01 23:31:47

它不是相对的,它尊重您来自上层的 RewriteBase,其中 / ...
只需要在site2下放入htaccess即可

RewriteBase /site2/

it is not relative it respect you RewriteBase from upper level where is / ...
Just put in htaccess under site2

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