开发者

.htaccess combined 301 redirect, and URI rewriting

I've got a very simple .htaccess file that enables the rewrite engine, and lets me use URI's in my web applications.

The problem is i need to do a 301 redirect to get my webaddress without www redirected to my website WITH www (While keeping the current rewrite function that redirects every subdirectory access to index.php in the root of my domain), to optimize seo. I just can't get it to work. :(

开发者_运维问答So in short terms i need to combine the current code which is:

RewriteEngine on
RewriteRule ^(.+)/$ index.php

With the 301 rewrite rule which is

RewriteEngine on
RewriteCond %{HTTP:Host} ^website\.com$
RewriteRule (.*) http\://www.website.com$1 [NC,R=301]

My server is running Apache, with the mod rewrite enabled.

Thanks in advance


You don't make it entirely clear except in your example that your using php, however, using Helicon ISAPI Rewrite for IIS / .NET I use:

RewriteCond %{HTTP:Host} ^website\.com$

RewriteRule (.*) http\://www.website.com$1 [NC,R=301]


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

Reference: http://www.rlmseo.com/blog/htaccess-rewrite-www/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜