试图得到

www.example.com

直接转到

www.example.com/store

我已经尝试了多个代码位,但没有工作。

我的尝试:

Options +FollowSymlinks
RewriteEngine on

RewriteCond %{HTTP_HOST} ^example.com$
RewriteRule (.*) http://www.example.com/$1 [R=301,L]

RewriteCond %{HTTP_HOST} ^(.+)\www.example\.com$
RewriteRule ^/(.*)$ /samle/%1/$1 [L]

我做错了什么?


当前回答

如果你想重写URL并隐藏原始URL,另一个选择:

RewriteEngine on
RewriteRule ^(.*)$ /store/$1 [L]

例如,如果您键入http://www.example.com/product.php?id=4,它将透明地打开http://www.example.com/store/product.php?id=4文件,但不会向用户显示完整的url。

其他回答

如果你想重写URL并隐藏原始URL,另一个选择:

RewriteEngine on
RewriteRule ^(.*)$ /store/$1 [L]

例如,如果您键入http://www.example.com/product.php?id=4,它将透明地打开http://www.example.com/store/product.php?id=4文件,但不会向用户显示完整的url。

你可以使用一个重写规则,使用^$来表示根目录,并将其重写到你的/store目录,如下所示:

RewriteEngine On
RewriteRule ^$ /store [L]

上述大多数解决方案都是正确的,但它们都缺少重定向的透明性。

在我的例子中,当访问www.example.com时,我想重定向到子目录/store,但不更新URL到www.example.com/store。(所有我想要的是获得该目录的页面代码)。如果这是你的情况,下面的解决方案是完美的。

RewriteEngine on
RewriteCond %{HTTP_HOST} example\.com [NC]
RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^(.*)$ /store/$1 [L]

来源:http://wiki.dreamhost.com/Transparently_redirect_your_root_directory_to_a_subdirectory

尝试在htaccess中使用下面的行

注意:你可能需要检查default.html的名称是什么

html是根文件夹中默认加载的文件。

RewriteEngine

重定向/default.html http://example.com/store/

这似乎是最简单的解决方案:

RewriteEngine on
RewriteCond %{REQUEST_URI} ^/$
RewriteRule (.*) http://www.example.com/store [R=301,L]

我得到了重定向循环和一些其他的解决方案。