Help with mod_rewrite and mod_redirect

后端 未结 1 906
隐瞒了意图╮
隐瞒了意图╮ 2021-01-28 14:49

My .htaccess file is:

Redirect 301    http://domain.com/news/articles?dtMain_start=150    http://domain.com/news/articles
Redirect 301    http://domain.com/news/         


        
1条回答
  •  有刺的猬
    2021-01-28 15:35

    First of all: There is not mod_redirect. Redirect is a directive of mod_alias.

    And the Redirect directive, like any other directive of mod_alias, does only work with the URL path. So your Redirect directives won’t work as expected. Use mod_rewrite equivalents instead:

    RewriteCond %{HTTP_HOST} =example.com
    RewriteRule (.*) http://www.example.com/$1 [R=301,L]
    
    RewriteCond %{QUERY_STRING} ^dtMain_start=(150|160|170)$
    RewriteRule ^news/articles$ /news/articles? [L,R=301]
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
    

    In general it is not a good idea to mix mod_alias and mod_rewrite if the patterns coincide with each other.

    0 讨论(0)
提交回复
热议问题