简体   繁体   English

mod_rewrite重定向到干净的URL

[英]mod_rewrite redirect to clean URLs

I'm using mod_rewrite in my .htaccess to create the following clean URLs. 我在.htaccess中使用mod_rewrite创建以下干净的URL。

.htaccess 的.htaccess

RewriteEngine On
RewriteRule ^home$ /index.php [L]
RewriteRule ^groups$ /groups.php [L]
RewriteRule ^contact$ /contact.php [L]
RewriteRule ^personalise$ /personalise.php [L]
RewriteRule ^terms$ /terms.php [L]

All works well however I've been trying to get the original links to redirect to the smooth links. 一切正常,但是我一直在尝试将原始链接重定向到平滑链接。 For example, if someone visits www.mydomain.com they'll be redirected to www.mydomain.com/home and likewise if they trail the domain with index.php or any other page name. 例如,如果有人访问www.mydomain.com他们将被重定向到www.mydomain.com/home ,同样,如果他们使用index.php或任何其他页面名称跟踪该域,则将其重定向。

I've had a look at a few different rules that don't seem to work, I'm not very familiar with the module. 我看了一些似乎不起作用的不同规则,我对该模块不是很熟悉。 Any ideas would be much appreciated! 任何想法将不胜感激!

I am giving you 2 of these new rules: 我给您这些新规则中的2条:

  1. To redirect index.php to /home index.php重定向到/home
  2. To remove .php extension 删除.php扩展名

Your full .htaccess: 您的完整.htaccess:

RewriteEngine On

RewriteCond %{THE_REQUEST} \s/+index\.php[\s?] [NC]
RewriteRule ^ /home [R=301,L,NE]

RewriteCond %{THE_REQUEST} \s/+(.*?)\.php[\s?] [NC]
RewriteRule ^ /%1 [R=301,L,NE]

RewriteRule ^home$ /index.php [L]
RewriteRule ^groups$ /groups.php [L]
RewriteRule ^contact$ /contact.php [L]
RewriteRule ^personalise$ /personalise.php [L]
RewriteRule ^terms$ /terms.php [L]

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

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