简体   繁体   中英

How to ReWriteRule and then Redirect 301 it using .htaccess

I want to rid off .php and create a SEO friendly url. here is the scenario:

examplesite.com/platform/sign-in.php should be displayed / accessible in examplesite.com/platform/login/

the following rule makes that happen. now I can visit to the examplesite.com/platform/sign-in.php just by visiting to examplesite.com/platform/login/

RewriteRule    ^platform/login/?$    platform/sign-in.php [NC,L]

examplesite.com/platform/login/ is my login page now but this page examplesite.com/platform/sign-in.php stays same. I can visit to examplesite.com/platform/sign-in.php as well. So I tried this redirection to redirect the users to examplesite.com/platform/login/ if they visit to examplesite.com/platform/sign-in.php

Redirect 301    /platform/sign-in.php /platform/login/

Now when I visit to examplesite.com/platform/sign-in.php it says too many redirections and loads nothing.

how to solve this? examplesite.com/platform/sign-in.php should be auto redirect to examplesite.com/platform/login/

Try this:

RewriteRule ^platform/login/?$ /platform/sign-in.php [NC,L]

RewriteCond %{THE_REQUEST} \s/platform/sign-in.php
RewriteRule ^platform/sign-in.php /platform/login/ [NC,R=301,L]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM