Redirect one url to another url using .htaccess

后端 未结 4 507
醉酒成梦
醉酒成梦 2020-12-10 21:22

As i am trying to redirect one complete URL

http://www.domain-name.com/download/?page=download

To this URL

http://www.dom         


        
相关标签:
4条回答
  • 2020-12-10 21:43

    you can use this rule

    Redirect /download/?page=download http://www.domain-name.com/download/show
    
    0 讨论(0)
  • Redirect One URL to Another URL by Using htaccess file:

    Redirect 301 /en/php/project.html http://www.example.org/newpage.html
    
    0 讨论(0)
  • 2020-12-10 21:58

    Use RewriteEngine:

    RewriteEngine On
    Redirect 301 http://www.domain-name.com/download/?page=download http://www.domain-name.com/download/show
    
    0 讨论(0)
  • 2020-12-10 22:02

    RewriteRule doesn't include the query string and doesn't include the http-host. Besides that, the first argument is a regex pattern. Without the http host you would be matching either download/page=download(etc) or downloadpage=download(etc).

    You'll need 2 rules. One that redirects the ugly url to the nice url. One rule needs to rewrite the nice url to an actual working url:

    #Rewrite ugly url to nice url
    RewriteCond %{QUERY_STRING} ^page=download&?(.*)$
    RewriteRule ^download/?$ download/show?%1 [R,L]
    
    #Now get the nice url to work:
    RewriteRule ^download/show/?$ download/?page=download [QSA,END]
    

    The second rule uses the QSA flag, which means it will append the original query string to the query string in the rewriterule. The END flag stops all rewriting, as the L-flag doesn't do that in .htaccess context. END is only available from Apache 2.3.9 onwards and will cause an internal server error if used in an version before that. Please note that you probably have to modify the second rule to point to an actual file.

    You can find the documentation here.

    Edit: Please note that you should NEVER test htaccess rules with a PERMANENT redirect. If you make a mistake, the browser will remember this mistake! Only convert temporary redirects to permanent redirects if everything is working as you expect it to work.

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