【问题标题】:.htaccess redirecting index.php to home without redirecting subdomain.htaccess 将 index.php 重定向到主页而不重定向子域
【发布时间】:2014-01-07 15:52:58
【问题描述】:

这是我目前的整个 .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。

如何防止子域被重定向?

【问题讨论】:

    标签: .htaccess redirect subdomain


    【解决方案1】:

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

    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]
    

    【讨论】:

    • 空格后的部分起作用。第一部分不会重定向到 codeliger.com/home
    • 第一个规则无效的完整 URL 是什么?
    • 重申一下,当您在浏览器中输入http://www.codeliger.com/index.php 时,它将重定向到/home
    • 如何让它在没有 index.php 的情况下将 codeliger.com 重定向到 /home
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-05-14
    • 2016-11-22
    • 2016-01-17
    • 2018-06-02
    • 2013-01-21
    • 2014-08-31
    • 1970-01-01
    相关资源
    最近更新 更多