试图得到

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]

我做错了什么?


当前回答

如果文件在根目录中不存在,这将尝试子目录。需要这个,因为我移动了一个基本的。html网站,期望在根级运行,并将其推到一个子目录。只有在所有文件都是平面的情况下才有效(在子目录中不可能使用.htaccess技巧)。对于css和js文件这样的链接文件很有用。

# Internal Redirect to subdir if file is found there.
RewriteEngine on
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_URI} !-s
RewriteCond %{DOCUMENT_ROOT}/subdir/%{REQUEST_URI} -s
RewriteRule ^(.*)$ /subdir/$1 [L]

其他回答

尝试在htaccess中使用下面的行

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

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

RewriteEngine

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

这是我用来重定向到子目录的。这是无形的,但仍然允许通过匹配现有文件或其他文件的请求。

RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?site.com$
RewriteCond %{REQUEST_URI} !^/subdir/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /subdir/$1
RewriteCond %{HTTP_HOST} ^(www.)?site.com$
RewriteRule ^(/)?$ subdir/index.php [L]

用你的值替换site.com和subdir。

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

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

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

如果文件在根目录中不存在,这将尝试子目录。需要这个,因为我移动了一个基本的。html网站,期望在根级运行,并将其推到一个子目录。只有在所有文件都是平面的情况下才有效(在子目录中不可能使用.htaccess技巧)。对于css和js文件这样的链接文件很有用。

# Internal Redirect to subdir if file is found there.
RewriteEngine on
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_URI} !-s
RewriteCond %{DOCUMENT_ROOT}/subdir/%{REQUEST_URI} -s
RewriteRule ^(.*)$ /subdir/$1 [L]

我不明白你的问题……

如果你想重定向每个请求到一个子文件夹:

RewriteRule ^(.*)$ shop/$1 [L,QSA]

http://www.example.com/* -> wwwroot/store/*

如果要重定向到具有域名的子文件夹

RewriteCond %{HTTP_HOST} ([^\.]+\.[^\.]+)$
RewriteRule ^(.*)$ %1/$1 [L,QSA]

http://www.example.com/* -> wwwroot/example.com/*