htaccess仅用于www重定向

时间:2009-12-29 06:56:26

标签: .htaccess

我有什么方法可以将我的网址重定向到只使用http://www.domain.com而不是http://domain.com

这是我的htaccess但不起作用:

# Turn on URL rewriting
RewriteEngine On

# Installation directory
# RewriteBase /test/
Options +FollowSymlinks

# Protect application and system files from being viewed
RewriteRule ^(application|modules|system) - [F,L]

# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# Rewrite all other URLs to index.php/URL
RewriteRule .* index.php/$0 [PT,L]

#redirec

#detect urls without www
RewriteCond %{http_host} ^thehotelinventory.com [NC]

#redirect to www, does not work though
RewriteRule ^(.*)$ http://www.thehotelinventory.com/$1 [R=301,L] 

AddHandler php5-script .php

2 个答案:

答案 0 :(得分:3)

如果您需要从非www重定向到www,则重定向到HTTPS以获取不支持SSL上的www非www的THAWTE等证书。

RewriteEngine On
#non-www to www
RewriteCond %{HTTP_HOST} ^yourdomain.com
RewriteRule (.*) http://www.yourdomain.com/$1 [R=301,L]

#Redirect to HTTPS before www redirect
RewriteEngine on
RewriteCond %{HTTPS}
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]

感谢Brasil na Web Dev。人

答案 1 :(得分:0)

这里可以找到一个简单的答案:http://snippets.dzone.com/posts/show/2264