.htaccess将index.php重定向到home而不重定向子域

时间:2013-12-19 07:18:27

标签: .htaccess redirect subdomain

这是我目前的整个.htaccess文件:

  RewriteEngine on
  Redirect /index.php /home
  RewriteRule ^home$ /index.php?page=home
  RewriteRule ^education$ /index.php?page=home&filter=1
  RewriteRule ^skills$ /index.php?page=home&filter=2
  RewriteRule ^projects$ /index.php?page=home&filter=3
  RewriteRule ^experience$ /index.php?page=home&filter=4
  RewriteRule ^contact$ /index.php?page=contact

我目前正在使用顶部重定向来重定向: www.codeliger.com/index.php到www.codeliger.com/home看起来更好。 (有更好的方法吗?)

问题是它还将img.codeliger.com重定向到codeliger.com/home。

如何防止重定向子域?

1 个答案:

答案 0 :(得分:2)

是的,您可以将第一条规则替换为:

RewriteCond %{HTTP_HOST} ^(www\.)?codeliger\.com$ [NC]
RewriteCond %{THE_REQUEST} \s/(index\.php)?[\s?] [NC]
RewriteRule ^ /home? [L,R]

RewriteRule ^home/?$ /index.php?page=home [L]
RewriteRule ^education/?$ /index.php?page=home&filter=1 [L]
RewriteRule ^skills/?$ /index.php?page=home&filter=2 [L]
RewriteRule ^projects/?$ /index.php?page=home&filter=3 [L]
RewriteRule ^experience/?$ /index.php?page=home&filter=4 [L]
RewriteRule ^contact/?$ /index.php?page=contact [L]