重定向到子文件夹

时间:2011-04-08 15:46:11

标签: apache .htaccess redirect

我已经在我的主机上设置了网址重定向 - 但它无效。 我的htaccess现在看起来像这样

rewriteengine on
rewritecond %{HTTP_HOST} ^.*$
rewriterule ^http:\/\/www\.bangkoksoftball\.info "http\:\/\/www\.bangkoksoftball\.info\/wordpress" [R=301,L] #4d3a8d4534e567

我想要的是http://www.bangkoksoftball.info被重定向到http://www.bangkoksoftball.info/wordpress/的任何请求

但是对根目录下的路径文件或目录的任何请求都不会被重定向

这样人们仍然可以通过/home.html或index.html等访问旧网站..并且仍然可以在wordpress文件夹之外导航

3 个答案:

答案 0 :(得分:1)

在.htaccess文件中尝试此操作:

RewriteEngine on
Options +FollowSymLinks
RewriteCond %{HTTP_HOST} ^(www\.)?bangkoksoftball\.info$ [NC]
RewriteRule ^/?$ /wordpress/ [R,L,NE]

请记住%{HTTP_HOST}或%{REQUEST_URI}变量中存在 http / https。此外,.也需要在域匹配中进行转义。 NE标志用于不转义查询参数。

答案 1 :(得分:0)

rewriterule行不查看域,您必须在RewriteCond行中指定规则适用的域。在rewriterule行中,首先指定应该触发规则的路径,以及用户应该发送到的路径。

RewriteEngine on
RewriteCond %{HTTP_HOST} ^http:\/\/www\.bangkoksoftball\.info$
RewriteRule ^/$ "http\:\/\/www\.bangkoksoftball\.info\/wordpress" [R=301,L]

这只会向www.bangkoksoftball.info/发送请求到wordpress文件夹。如果您还想将www.bangkoksoftball.info/index.php重定向到wordpress文件夹,则需要添加一组额外的指令:

RewriteCond %{HTTP_HOST} ^http:\/\/www\.bangkoksoftball\.info$
RewriteRule ^/index\.php$ "http\:\/\/www\.bangkoksoftball\.info\/wordpress" [R=301,L]

答案 2 :(得分:-1)

这应该对你有用here

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?bangkoksoftball.info$ [NC]
RewriteRule ^/$ http://www.bangkoksoftball.info/wordpress/$1 [R=301,L]