一个 .htaccess 文件中有多个 RewriteBase?
我在同一台服务器上有一个域和一个 WordPress 博客。现在我有一个问题(惊讶)。 wordpress 位于 /httpdocs/blog/ ,域指向 /httpdocs/,我试图将其重定向到 /httpdocs/domain/。但是,显然,我在 Wordpress 中有永久链接。
这是我当前的 .htaccess:
RewriteEngine On
RewriteBase /blog/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
RewriteBase /
RewriteCond %{HTTP_HOST} domain.com
RewriteCond %{REQUEST_URI} !^/domain
RewriteCond %{REQUEST_URI} !^/cgi-bin
RewriteRule ^(.*)$ domain/$1 [L]
但正如您已经假设的那样,这不起作用。 WordPress 的永久链接也会影响 /domain/,因此我的图像和其他网址会出错。
有什么建议吗?可以这样使用RewriteBase吗?
I have a domain and a wordpress-blog on same server. Now I have a problem (surprise). The wordpress is located on /httpdocs/blog/ and domain is pointing to /httpdocs/ and I'm trying to redirect it to /httpdocs/domain/. But, obvisiously, I have permalinks in Wordpress.
Here's my current .htaccess:
RewriteEngine On
RewriteBase /blog/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
RewriteBase /
RewriteCond %{HTTP_HOST} domain.com
RewriteCond %{REQUEST_URI} !^/domain
RewriteCond %{REQUEST_URI} !^/cgi-bin
RewriteRule ^(.*)$ domain/$1 [L]
But as you already propably assumed, this doesn't work. Wordpress' permalinks affects to /domain/ also, so my images and other urls go wrong.
Any advice? Is it possible to use RewriteBase like this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不可以,您只能有一个基本 URL。只需重写您的规则:
No, you can only have one base URL. Just rewrite your rules:
当我试图寻找类似问题的解决方案时,我来到了这篇文章。看起来基本URL可以不止一个,但是重写后逻辑并没有停止。如果 URL 命中两个重写基,则所有重写都将运行。因此,最严格的重写基数应该放在文件的末尾。对于这个例子,它应该是:
请注意,由于两个重写都正在运行,所以如果重写矛盾,您将需要回退到接受的答案。
I come to this post when I am trying to find solution for a similar problem. It seems that there can be more then one base URL, but the logic does not stop after rewrite. If the URL hit both rewrite base, all the rewrite will be run. Therefore, the strictest rewrite base should be put at the end of the file. For this example, it should be:
Noticed that as both rewrite are being run, so if the rewrite contradicts, you will need to fall back to the accepted answer.