.htaccess从子文件夹重定向到域名 [英] .htaccess redirect FROM subfolder to domain name
问题描述
我在子文件夹中有网站内容( http://mydomain.com/subfolder/index.php ),现在我将所有内容复制到了根文件夹( http://mydomain.com/index.php )。
I had website content in a subfolder (http://mydomain.com/subfolder/index.php), now I copied everything over to the root folder (http://mydomain.com/index.php).
我想使用重定向所有将旧页面添加为书签的访问者,使其指向新内容(至少指向新index.php)。 htaccess。
I would like to redirect all the visitors that have bookmarked the old page to the new content (at least to the new index.php) using .htaccess.
是否正确:
RewriteEngine on
RewriteRule /subfolder/^(.*)$ http://mydomain.com [R=301,L]
?
我将.htaccess文件放在子文件夹或根文件夹中的什么位置?
And where would I place the .htaccess file, in the subfolder or the root folder?
推荐答案
将以下 .htaccess
放入 /
(其中的索引.php位于)应该可以解决问题:
Placing the following .htaccess
in /
(where your index.php is located) should do the trick:
RewriteEngine on
RewriteRule ^subfolder/(.*)$ /$1 [R=301,L]
或者您可以将以下 .htaccess
放在 /子文件夹
:
Or you could place the following .htaccess
in /subfolder
:
RewriteEngine On
RewriteRule ^(.*)$ /$1 [R=301,L]
请注意,()
。*
和 $ 1
重定向 /subfolder/someFile.php
到 /someFile.php
。如果您跳过它,则 /子文件夹
中的所有内容都会重定向到 /
。
Note that the ()
around .*
and the $1
redirects /subfolder/someFile.php
to /someFile.php
. If you skip it, everything in /subfolder
redirects to /
.
这篇关于.htaccess从子文件夹重定向到域名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!