.htaccess to Redirect All Traffic to One Page (410 Gone)

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-04 01:33:09

问题


We have a client that is closing its doors. We want to redirect all traffic that goes to their domain to a new page index.html with a few images in the _img subdirectory. (The page explains what happened, what current customers can expect with their current orders, etc.)

I've read about possibly using HTTP 410 Gone as the best way to technically explain to bots, etc. that the site is not there, isn't coming back and isn't providing a forwarding address. What would be the best way to do this in an .htaccess file, and direct users to the new index.html?


回答1:


You can use mod_rewrite for this.

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule !^index\.html$ index.html [L,R=410]

This rule will rewrite requests to non-existing files to index.html and send the 410 status code along with the response. But this requires Apache 2 as R=4xx is only available since Apache 2.




回答2:


You can simply use an .htaccess file like this:

<IfModule mod_rewrite.c>
   RewriteEngine on
   RewriteCond %{REQUEST_URI} !.*index\.php
   RewriteRule (.*) /index.php
</IfModule>



回答3:


This is much simpler:

RedirectMatch temp .* http://www.newdomain.com/newdestination.html

It redirects every single request to newdestination.html.

Note that if you point to the same domain as the source, there will be an infinite loop and this will fail. This works great pointing to a new domain, though.



来源:https://stackoverflow.com/questions/1975904/htaccess-to-redirect-all-traffic-to-one-page-410-gone

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!