【问题标题】:Internal url rewriting with Apache使用 Apache 重写内部 url
【发布时间】:2015-11-04 17:57:40
【问题描述】:

我正在尝试将http://example.com/tel.php 上的请求重定向到http://example.com/default/index/tel,而不向用户显示任何重定向。我在 htaccess 中这样做:

RewriteEngine On

RewriteRule ^tel\.php$ /default/index/tel [NC,L]


RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

但是我试图避免重定向显示给用户(HTTP/1.1 301 永久移动)。

如何解决?

【问题讨论】:

标签: apache .htaccess mod-rewrite redirect


【解决方案1】:

更改规则的顺序,如果

RewriteEngine On

RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

RewriteRule ^tel\.php$ /default/index/tel [NC,L]
# make it as this if /default/index/tel/ is a real directory
# RewriteRule ^tel\.php$ /default/index/tel/ [NC,L]

请务必在清除浏览器缓存后对其进行测试。

【讨论】:

    猜你喜欢
    • 2013-06-09
    • 1970-01-01
    • 1970-01-01
    • 2011-11-10
    • 2017-04-20
    • 1970-01-01
    • 1970-01-01
    • 2012-12-21
    • 1970-01-01
    相关资源
    最近更新 更多