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
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 关于#qt#的问题:Qt代码的移植问题
  • ¥50 求图像处理的matlab方案
  • ¥50 winform中使用edge的Kiosk模式
  • ¥15 关于#python#的问题:功能监听网页
  • ¥15 怎么让wx群机器人发送音乐
  • ¥15 fesafe材料库问题
  • ¥35 beats蓝牙耳机怎么查看日志
  • ¥15 Fluent齿轮搅油
  • ¥15 八爪鱼爬数据为什么自己停了
  • ¥15 交替优化波束形成和ris反射角使保密速率最大化