apache - Using a .htaccess to RewriteRule and Redirect 301 at the same time? -


I have certain URLs that I want to display on my website differently. For example, I have to be "/ contact.php" "/ contact". So I have added it to my .htaccess:

  rewrite ^ contact.php  

and pointing to the same page, 2 different URLs To avoid having, I also want to redirect a 301 between the old URL and the new one:

  301 / contact.php redirect http://www.example.com/contact  

Each row above works well differently but if I add them both to my htaccess, There is a yoke loop. How can I fix this?

Finally, if I type "/ contact" or "/contact.php", then I want to see the contact page with the URL "/contact".


Edit: I also tried to do such things, and it does not work:

  Rewriteum ^ / contact \ .php $ http: //www.example. Com / Contact [R = 301, L] Rematerialized Rules ^ / Contact $ / Contact PHP [L]  

Yes, it will actually cause redirection loop The mod_rewrite rules are applied in a loop. REQUEST_URI value contact.php after the first rule and contact according to your second rule.

To avoid this loop, use the THE_REQUEST variable in your external redirect rule % {THE_REQUEST} to get the original request you received from your browser. Need to be displayed and after writing some other rules, it has not been overwritten. The example value of this variable is GET /index.php?id=123 HTTP / 1.1 .

Use this:

  Revert engine #% / THE_REQUEST} \ s / + (contact) from the contact / rewrite converter with external /contact.php Php \ [\ s?] [NC] rewritable ^ /% 1? [R = 302, L] # Contact / contact / to contact. PHP Rewritable ^ (Contact) /? Make sure it's okay for you at $ $ 1.php [L, NC]  

Change to 302 to 301 doing work.


Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -