.htaccess rewrite rule rewriting 301 redirects

前端 未结 2 690
长情又很酷
长情又很酷 2021-01-21 10:29

I have a problem with my .htaccess redirects. I have both a rewrite rule to remove the \"index.php?/\" from my URLs (I\'m using a PHP framework), and also 301 redirects redirect

相关标签:
2条回答
  • 2021-01-21 10:49

    OK, I've come up with a couple of solutions.

    The first is to send the redirect in the example to

    Redirect 301 /oldpage.html http://www.example.com/index.php?/old_page
    

    This does not apply the rewrite removing the "index.php?", but it does work.

    The second work around is to edit the rewrite conditions to exclude any .php or .html files:

    RewriteCond $1 !^([a-zA-Z1-9\-\_/]*\.php$|assets|[a-zA-Z1-9\-\_/]*\.html$)
    

    This may also exluce any URLs that end in .php or .html, meaning the rewrite won't work, and your framework will break, but as long as you stay away from that you should be ok.

    0 讨论(0)
  • 2021-01-21 10:50

    Your issue is that this line: RewriteRule ^(.*)$ /index.php?/$1 [L] forces a query parameter in that rewrite. Some hosts are setup this way, one I know of in particular is DreamHost. So, anything that is redirected appears broken.

    You can try this

    RewriteRule ^dir/file.php$ http://webpage/newdir/file2.php [R=301,L]

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