开发者

Domain .htaccess redirect issue

开发者 https://www.devze.com 2023-03-22 08:42 出处:网络
I\'m trying to create some redirects with .htaccess but I never manage to get it fully functional. Maybe someone here can help me.

I'm trying to create some redirects with .htaccess but I never manage to get it fully functional. Maybe someone here can help me.

What I need is:

  1. htt开发者_开发百科p://domain.se and http://domain.com to redirect to http://www.domain.com.

  2. I also need http://domain.se/somefolder, http://domain.com/somefolder as well as http://www.domain.se/somefolder to redirect to http://www.domain.com/folder.

I've tried to accomplish this myself but all I end up with is errors about data not being sent.


Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /

# folder rewrite
RewriteRule ^somefolder$ folder [L]

# domain redirect
RewriteCond %{HTTP_HOST} =domain.com [OR]
RewriteCond %{HTTP_HOST} =domain.se
RewriteRule (.*) http://www.domain.com/$1 [R=301,L]
  1. This is to be placed in .htaccess file in website root folder. If placed elsewhere some tweaking may be required.

  2. First rule will rewrite (internal redirect) requests to /somefolder to /folder. If you need this to be 301 Permanent Redirect, then replace [L] by [R=301,L]

  3. Second rule will do domain redirect job. This rule will ONLY redirect if domain is domain.com or domain.se. If you want to have redirect from ANY domain name (that your webserver is configured can serve) to www.domain.com then replace those 2 RewriteCond lines with this one: RewriteCond %{HTTP_HOST} !=www.domain.com.


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

That should meet all of your requirements. All requests that are not www.domain.com will be redirected to that domain, with the request URI intact.

0

精彩评论

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

关注公众号