【问题标题】:Redirecting url with get variables using htaccess使用 htaccess 使用 get 变量重定向 url
【发布时间】:2014-03-17 20:47:02
【问题描述】:

我正在尝试重定向此链接:http://www.example.com/articles.php?article_title=this-is-an-article

http://www.example.com/articles/this-is-an-article

这是我目前在我的 .htaccess 文件中所拥有的似乎不起作用的内容:
重写引擎开启 重写基础/

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

RewriteRule ^articles/([a-z\-]+)$ articles.php?article_title=$1


在此先感谢

【问题讨论】:

    标签: .htaccess redirect


    【解决方案1】:

    试试这个代码:

    Options -Indexes -MultiViews
    RewriteEngine On
    
    RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
    RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [L,R=301]
    
    RewriteCond %{THE_REQUEST} \s/+articles\.php\?article_title=([^&\s]+) [NC]
    RewriteRule ^ /articles/%1? [R=301,L,NE]
    
    RewriteRule ^articles/([a-z-]+)/?$ articles.php?article_title=$1 [L,QSA,NC]
    

    【讨论】:

    • 您需要详细说明什么不起作用?还有其他规则吗?
    • 当尝试访问重写的 url 时,我收到一个 404 错误,指出找不到 article.php 文件。不,只是我提到的那些。
    • 这个 .htaccess 的位置是什么?通过将相同的垃圾(随机)文本放在您的 .htaccess 顶部来验证您的 .htaccess 是否启用,并查看它是否会生成 500(内部服务器)错误?
    • 对不起,规则很好(你的和我的)当我改变浏览器时它们起作用了,我认为这是某种缓存或其他东西,但我还有一个问题是访问的能力旧链接,会导致内容重复的问题。
    • 您希望使用 301 重定向到新链接的旧链接是什么?
    猜你喜欢
    • 1970-01-01
    • 2013-09-19
    • 1970-01-01
    • 2012-05-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多