使用mod_rewrite从example.com/dir重定向到www.example.com/dir~~V [英] Use mod_rewrite to redirect from example.com/dir to www.example.com/dir
问题描述
假设/是我的域名example.com的文档根目录。
Assume / is the document root of my domain example.com.
/的.htaccess
/.htaccess
RewriteEngine on
RewriteCond %{HTTP_HOST} ^golfcoursesd\.com$ [NC]
RewriteRule ^(.*)$ http://www.golfcoursesd.com/$1 [R=301,L]
/dir/.htaccess
/dir/.htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /dir/index.php [L]
</IfModule>
我知道如何重定向example.com/dir到www.example.com/dir~~V,因为/.htaccess做的非常的工作。
I know how to redirect example.com/dir to www.example.com/dir, because /.htaccess does the very job.
然而,这里的技巧是我要保持/dir/.htaccess来提供虚拟目录(如/ DIR /国家/ AK / 35827 /这是不实际的目录),如果你知道我的意思。
However, the trick here is that I have to keep /dir/.htaccess to serve up virtual directories (such as /dir/state/AK/35827/ which aren't actual directories) if you know what I mean.
但问题是,如果我继续/dir/.htaccess,一个请求:
Problem is, if I keep /dir/.htaccess, a request of:
http://example.com/dir/state/AK/35827/
不重定向到:
http://www.example.com/dir/state/AK/35827 /
和会:
重定向到:
不知道我是否清楚。
基本上,如何让 http://example.com/dir/state/AK/ 35827 / 正确地重定向到 http://www.example.com/dir /国家/ AK / 35827 / ,我可以成为虚拟的网址?
Basically, how to make http://example.com/dir/state/AK/35827/ correctly redirect to http://www.example.com/dir/state/AK/35827/ AND I can serve virtual URLs?
推荐答案
如果你有机会到Apache VirtualHosts的配置,那么你需要的:
If you do have access to your apache VirtualHosts configuration then you need:
<VirtualHost *:80>
ServerName example.com
Redirect permanent / http://www.example.com/
</VirtualHost>
这将成功地重定向 http://example.com/ 到的 http://www.example.com/ 和的 http://example.com/dir/state/AK/35827/ 到的 http://www.example.com/dir/state/AK/35827/
This will succesfully redirect http://example.com/ to http://www.example.com/ and http://example.com/dir/state/AK/35827/ to http://www.example.com/dir/state/AK/35827/
这篇关于使用mod_rewrite从example.com/dir重定向到www.example.com/dir~~V的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!