阿帕奇的.htaccess mod_rewrite的,干净的网址 [英] Apache .htaccess mod_rewrite and clean urls

查看:180
本文介绍了阿帕奇的.htaccess mod_rewrite的,干净的网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

确定。所以我建立这个网站是通过两个不同的域进行访问。因此,我不能在我的.htaccess使用的RewriteBase。规则(下)我用它来解决此问题似乎很好地工作。然而,当我用我的干净的URL(WAMP)本地框下面的.htaccess设置,这一切工作正常,但现在我用这个活的服务器(共享主机LAMP)每一页我浏览到显示器的主页(上之一的索引我想),即使在浏览器的URL显然正在更新

Ok. So I'm building this site which is accessible through two different domains. So I can't use RewriteBase in my .htaccess. The rules (below) I use to work around this problem seem to work fine. However, when I use the below .htaccess settings on my local box with clean URLS (WAMP) it all works fine but the moment I use this on the live server (shared hosting LAMP) every page I navigate to displays the home page (the one under index I guess) even though the URL in the browser is clearly being updated.

<IfModule mod_rewrite.c>
  RewriteEngine On

  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_URI} ^/domain1.com/(.*)$
  RewriteRule ^(.*)$ /domain1.com/index.php?q=$1 [L,QSA]

  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_URI} ^/domain2.com/(.*)$
  RewriteRule ^(.*)$ /domain2.com/index.php?q=$1 [L,QSA]
</IfModule>

任何帮助或想法都非常AP preciated。

Any help or ideas are very much appreciated.

  • 卢克

推荐答案

大概是做的最好的事情是重现该问题在您的本地框和转起来RewriteLogLevel所以你可以看到发生了什么事情。 (因为你通常不能更改共享主机的日志级别)

Probably the best thing to do is to reproduce the problem on your local box and turn up RewriteLogLevel so you can see what's going on. (Since you usually can't change the log level on shared hosting)

您可以通过做一个目录重写你的Apache的主要配置为仿真的问题。 (共享托管显然是其自身的重写之前,它获取到的.htaccess!)如果您不能重现该问题,您可能需要启动远程服务器上的尝试和错误调试。这是丑陋的,但如果这是你唯一的选择:

You may be able to "simulate" the problem by doing a directory rewrite in your Apache main configuration. (The shared hosting obviously does its own rewriting before it gets to the .htaccess!) If you can't reproduce the problem, you may have to start trial-and-error debugging on the remote server. This is ugly but if it's your only option:

使用的R(重定向)标志替代发送任何重写URL回到你的浏览器。使用telnet(或相应的浏览器插件),以检查HTTP响应。

Use the R (redirect) flag in substitutions to send any rewritten URL back to your browser. Use TELNET (or an appropriate browser add-on) to inspect the HTTP responses.

不要忘了逃跑的点在正则表达式!

Don't forget to escape dots in regexes!

作为一个侧面说明,重写规则模式是它上面的RewriteConds之前匹配。这种设置是可能获得更好的性能:

As a side note, the RewriteRule pattern is matched before the RewriteConds above it. This kind of setup is probably better for performance:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/domain1\.com/(.*)$ /domain1.com/index.php?q=$1 [L,QSA]
#                     ^ should be escaped

请注意,我没有测试过这一点。

Note that I haven't tested this.

这篇关于阿帕奇的.htaccess mod_rewrite的,干净的网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆