将URL不存在的子文件夹重定向到root

时间:2013-06-15 21:16:17

标签: apache redirect rewrite

我已将我的网站从www.site.com/shop/子文件夹移至root。现在“商店”文件夹不再存在,我想将仍然访问site.com/shop/whateverhtml的人重定向到site.com/whateverhtml 我尝试了不同的重写规则,但没有运气。

RewriteEngine on
RewriteRule %{REQUEST_URI} ^/shop/.*
RewriteRule shop/(.*)$ /$1 [R=301,L]

或者像这样

RedirectMatch 301 ^/shop/$ http://site.com/

感谢。

2 个答案:

答案 0 :(得分:0)

<强>重定向

这需要您创建一个空的shop文件夹。 在该文件夹中,创建一个名为index.html的HTML文件。访问http://site.com/shop时,系统会将用户定向到此处。 在该文件中,输入:

<html>
<head>
<title>Redirecting...</title>
<meta http-equiv="refresh" content="0; url=http://site.com/">
</head>
<body>
You are being redirected...
</body>
</html>

这会将它们重定向到http://site.com/

<强>帧

您可以在页面上显示<iframe>的其他页面。 <iframe>在同一页面中显示另一个页面,但不重定向。您仍然需要保留商店文件夹。在其中,将index.html与此内容放在一起:

<html>
<head>
<title>Shop</title>
</head>
<body>
<iframe src="http://site.com/"></iframe>
</body>
</html>

这将创建一个包含site.com的iframe的页面

答案 1 :(得分:0)

RewriteCond %{REQUEST_URI} ^/shop(/.*)?$
RewriteRule ^(.*)$ %1 [R=301,L]

RewriteRule ^shop(/.*)?$ $1 [R=301,L]
相关问题