简体   繁体   English

.htaccess WordPress将URL重定向到特定文件

[英].htaccess wordpress redirect url to specific file

Hi i see all thread here but codes not work for my problem. 嗨,我在这里看到所有线程,但是代码无法解决我的问题。 I have a custom page landing.php (in root of wp site) and this is landing page with one link only (static page) 我有一个自定义页面landing.php(在wp网站的根目录中),这是仅具有一个链接的登陆页面(静态页面)

I want to site.com/landing.php redirect just to site.com/landing/ , but landing.php redirect to /landing 我想将site.com/landing.php重定向到site.com/landing/ ,但将landing.php重定向到/ landing

I try with this code: RewriteRule ^landing/?$ landing.php [L] 我尝试使用以下代码: RewriteRule ^landing/?$ landing.php [L]

But in this case i can open /landing/ and /landing.php, i want landing.php redirect to /landing/ 但是在这种情况下,我可以打开/ la​​nding /和/landing.php,我希望着陆.php重定向到/ landing /

Thanks 谢谢

It is a bit unclear what you actually want... 现在还不清楚您真正想要什么...

But this is the answer to what you specifically asked in the comment to your question: 但这是您在对问题的评论中具体要求的答案:

RewriteEngine on
RewriteRule ^/?landing\.php$ /landing/ [R=301]

That rule will work likewise in the real http server's host configuration and in a dynamic configuration file (".htaccess" style files). 该规则将在实际的http服务器的主机配置和动态配置文件(“ .htaccess”样式文件)中同样起作用。

A remark however: you should always prefer to place such rules in the http servers host configuration instead of using dynamic configuration files (".htaccess"). 但是请注意:您应该始终喜欢将此类规则放置在http服务器主机配置中,而不要使用动态配置文件(“ .htaccess”)。 Those dynamic configuration files add complexity, are often a cause of unexpected behavior, hard to debug and they really slow down the http server. 这些动态配置文件增加了复杂性,通常是导致意外行为,难以调试的原因,并且确实降低了http服务器的速度。 They are only provided as a last option for situations where you do not have access to the real http servers host configuration (read: really cheap service providers) or for applications insisting on writing their own rules (which is an obvious security nightmare). 仅当您无法访问真正的http服务器主机配置(阅读:真正便宜的服务提供商)或坚持编写自己的规则的应用程序(这显然是安全的噩梦)时,才提供它们作为最后的选择。

However considering what is typically done for simple web projects I guess this is what you are looking for: 但是考虑到简单Web项目通常要做的事情,我这就是您要寻找的东西:

RewriteEngine on
RewriteRule ^/?landing\.php$ /landing/ [R=301]
RewriteRule ^/?landing/?$ /landing.php [END]

In case you experience an internal server error using above rules (http status 500) then chances are that you operate a very old version of the apache http server. 如果您使用上述规则(http状态500)遇到内部服务器错误,则很可能是您运行了非常旧版本的apache http服务器。 You should try to upgrade, in case that is not possible have a try using the L flag instead of the END flag. 您应该尝试升级,以防无法尝试使用L标志而不是END标志。 It might work just fine depending on your setup. 根据您的设置,它可能工作正常。

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

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