Clean URL Redirect Loop

后端 未结 4 1395
暖寄归人
暖寄归人 2020-12-15 00:46

I\'m trying to create clean URLs on my website. Now I succeeded in configuring apache so every request like mysite.com/page will work. But I also want that requests

相关标签:
4条回答
  • another quick & dirty way to prevent looping in these situations i've found is to add a querystring and then check for its existence in the redirect.

    RewriteCond %{QUERY_STRING} !a=a
    RewriteRule ^(.*)\.php$ %1 [NC,R=301,L]
    RewriteRule ^(.*)$ $1.php?a=a [NC,L]
    

    found on this site: http://answers.oreilly.com/topic/542-how-to-properly-redirect-for-maximum-seo/

    0 讨论(0)
  • 2020-12-15 00:57

    Is there some reason why you can't use the end-of-string termination character, $ ?

    RewriteRule ^/(.+)\.php$ /$1
    

    will redirect /page.php to /page but will not do any redirecting on /page .

    Fundamentally, using techniques like setting environment variables and adding checks for REDIRECT_STATUS is not going to be very robust.

    0 讨论(0)
  • 2020-12-15 01:11

    Add this rule above your existing rewrite rules to stop redirecting if the request has already been redirected once (ref):

    RewriteCond %{ENV:REDIRECT_STATUS} 200
    RewriteRule .* - [L]
    
    0 讨论(0)
  • 2020-12-15 01:12

    You could check the request line for what has originally been requested:

    RewriteCond %{THE_REQUEST} ^[A-Z]+\ (/[^\ ]*)\.php[?\ ]
    RewriteRule \.php$ %1 [R=301,L]
    

    Oh, and the first argument of the RewriteCond directive is not a regular expression but just a string. So the escaping the . is wrong.

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