【问题标题】:htaccess Custom Redirects not workinghtaccess 自定义重定向不起作用
【发布时间】:2016-09-26 19:25:14
【问题描述】:

我一直在到处搜索,但似乎无法正常工作。

这段代码运行完美:

RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f

RewriteRule ^/?artists/[\w-]+/([\w-]+)/([\w-]+)/?$ /dir1/artist.php?artist_id=$1&page_id=$1 [L,QSA,NC]
RewriteRule ^/?tour/[\w-]+/([\w-]+)/?$ /dir2/index.php?artist_id=$1 [L,QSA,NC]
RewriteRule ^/?video/[\w-]+/([\w-]+)/?$ /dir3/index.php?artist_id=$1 [L,QSA,NC]
RewriteRule ^/?news/[\w-]+/([\w-]+)/?$ /dir4/article.php?artist_id=$1 [L,QSA,NC]

但是,在此之后,我在下面尝试了这个,并且服务器根本没有响应。它只是加载旧页面(仍在服务器上)

我的自定义重定向尝试,尝试过但不起作用

RedirectMatch 301 ^/old_dir//old_file.html /artists/subdir/21/biography/
RewriteRule /old_dir//old_file.html /artists/subdir/21/biography/ [L,R=301]

有人知道如何在第一个 RewriteRules 之后设置自定义重定向吗?

ps。甚至@anubhava 的回答都不起作用 (htaccess Redirects Not Working Right)

【问题讨论】:

    标签: php apache .htaccess redirect mod-rewrite


    【解决方案1】:

    您的正则表达式模式是301 规则的问题:

    RewriteEngine On
    
    RewriteRule ^old_dir/old_file\.html$ /artists/subdir/21/biography/ [L,R=301,NC]
    
    RewriteCond %{SCRIPT_FILENAME} -d [OR]
    RewriteCond %{SCRIPT_FILENAME} -f
    RewriteRule ^ - [L]
    
    RewriteRule ^/?artists/[\w-]+/([\w-]+)/([\w-]+)/?$ /dir1/artist.php?artist_id=$1&page_id=$1 [L,QSA,NC]
    RewriteRule ^/?tour/[\w-]+/([\w-]+)/?$ /dir2/index.php?artist_id=$1 [L,QSA,NC]
    RewriteRule ^/?video/[\w-]+/([\w-]+)/?$ /dir3/index.php?artist_id=$1 [L,QSA,NC]
    RewriteRule ^/?news/[\w-]+/([\w-]+)/?$ /dir4/article.php?artist_id=$1 [L,QSA,NC]
    

    顺便说一句,我认为这个问题与链接的答案没有关系(该答案用于添加 wwwhttps

    希望这次我的回答对你有用:)

    【讨论】:

    • 但你仍然是天才!非常感谢您解决这个问题!很抱歉没有正确阅读另一个问题。在这方面完全是文盲。
    猜你喜欢
    • 1970-01-01
    • 2015-03-07
    • 2015-08-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-03
    相关资源
    最近更新 更多