dongshi2836 2013-04-10 07:37
浏览 39
已采纳

重写URL www.domain.com在我的页面上导致404

Ok so I've rewrited URL in my website, now for some reason, it is throwing 404 error if I type www.domain.com, if I type domian.com, everything works fine.

DirectoryIndex home.php

IndexIgnore *
#RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
#RewriteRule ^(.*)$ http://%1/directory/$1 [L,R=301]

RewriteRule ^home/?$   home.php  [NC]
RewriteRule ^about/?$   about.php  [NC]

RewriteRule ^404/?$   404.php  [NC]

ErrorDocument 404 http://domain.com/directory/404

Note: I've commented the 1st 2 rewrite rules as even If I change them it doesn't effect after uploading .htaccess to server, feels like it's cached.

Additional Info, am using <base> tag which is in embeds.php

if($_SERVER['REMOTE_ADDR'] == '::1') {
    echo '<base href="http://localhost/projects/directory/" />';
} else {
    echo '<base href="http://domain.com/directory/" />';
}

Directory Structure

Root -
  home.php
  about.php
     -stylesheets
      default.css
     -includes
      embeds.php
  404.php
  .htaccess

embeds.php is included in home.php, about.php etc, and stylesheets, scripts etc, inshort the head section along with <base> tag are in embeds.php

  • 写回答

2条回答 默认 最新

  • douzhang5121 2013-04-10 07:48
    关注
    RewriteCond %{HTTP_HOST} ^domain.com$
    RewriteRule ^(.*) http://www.domain.com/$1  [QSA,L,R=301]
    

    It should work, if it dosn't it comes from your DNS, or Vhost configuration.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作