dqiz20794 2015-09-16 17:17
浏览 432
已采纳

如何将所有页面请求重定向到一个页面而不更改URL

I want to redirect all pages on my site (including index) to UnderWork.html and I'm doing this using .htaccess with this code:

RewriteEngine on
RewriteRule ^(.*)$ UnderWork.html

...and its works fine. Now I am adding some more code to my .htaccess to redirect all traffic to the non-www domain and now my code looks like this:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.domain\.in
RewriteRule ^(.*)$ http://domain.in$1 [R=permanent,L]
RewriteRule ^(.*)$ UnderWork.html

Here is where I have a problem. If I enter a URL like: domain.in/xyz then it works as before, but if I use a URL like: www.domain.in/xyz then Apache converts it to coincart.inxyz/.

What am I doing wrong here? How can I get what i want? Thanks in advance.

  • 写回答

1条回答 默认 最新

  • dongwa3808 2015-09-16 17:35
    关注

    Below are rules that work for me:

    RewriteEngine On
    
    # Adding trailing slash for directory requests.
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteCond %{REQUEST_URI} !^/www$
    RewriteCond %{HTTP_HOST} !^www\.
    RewriteRule ^(.+[^/])$ http://example.com/$1/ [R=permanent]
    
    # External redirection from www subdomain to non-www domain.
    RewriteCond %{HTTP_HOST} ^www\. [NC]
    RewriteRule ^/?(.*) http://example.com/$1 [L,R=permanent]
    
    # Internal redirection to index.php for nonexistent URLs.
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !\.(jpg|jpeg|png|gif)$
    RewriteRule . /index.php [L,QSA]
    

    To show a custom page when a directory root (domain root in particular) is requested, use the Apache's DirectoryIndex directive:

    DirectoryIndex UnderWork.html
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测