简体   繁体   English

如何ReWriteRule,然后使用.htaccess重定向301

[英]How to ReWriteRule and then Redirect 301 it using .htaccess

I want to rid off .php and create a SEO friendly url. 我想摆脱.php并创建一个SEO友好的URL。 here is the scenario: 这是场景:

examplesite.com/platform/sign-in.php should be displayed / accessible in examplesite.com/platform/login/ examplesite.com/platform/sign-in.php应该在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/ 现在,我只需访问examplesite.com/platform/sign-in.php即可访问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. examplesite.com/platform/login/现在是我的登录页面,但是此页面examplesite.com/platform/sign-in.php保持不变。 I can visit to examplesite.com/platform/sign-in.php as well. 我也可以访问examplesite.com/platform/sign-in.php So I tried this redirection to redirect the users to examplesite.com/platform/login/ if they visit to examplesite.com/platform/sign-in.php 所以,我想这重定向重定向用户examplesite.com/platform/login/如果他们参观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. 现在,当我访问examplesite.com/platform/sign-in.php它说重定向太多 ,什么也没有加载。

how to solve this? 如何解决呢? examplesite.com/platform/sign-in.php should be auto redirect to examplesite.com/platform/login/ examplesite.com/platform/sign-in.php应该自动重定向到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]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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