开发者

modrewrite - rewrite to new domain from subdirectory

开发者 https://www.devze.com 2023-03-29 06:40 出处:网络
Damn you modrewrite I have a website hosted at a url like: http://mydomain/mocks/thesite/ Now I want to move it to a new domain

Damn you modrewrite

I have a website hosted at a url like:

http://mydomain/mocks/thesite/

Now I want to move it to a new domain

http://thesitesdomain.com/

My htaccess looks like this:

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

Now this works fine as long as there is something after /mocks/thesite/. eg: http://mydomain/mocks/thesite/index.html redirects to http://www.thesitesdomain.com/index.php.

However the problem is that:

http://mydomain/mocks/thesite/ redirects to http://thesitesdomain.com/mocks/thesite/. Any idea why? How to stop this?

The .htacc开发者_StackOverflowess file is in the root of /mocks/thesite/ (if that helps)

Thank you


You should try to use the variable REQUEST_URI you might have a little more success with that. It should be the request uri and file name. To

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.thesitesdomain\.com
RewriteRule .* http://www.thesitesdomain.com/%{REQUEST_URI} [R=301,L]

I can't remember but to also redirect with the query string (get variables) I think you need to add it like this.

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.thesitesdomain\.com
RewriteRule .* http://www.thesitesdomain.com/%{REQUEST_URI}?%{QUERY_STRING} [R=301,L]

Been a while since really doing a domain redirect....

BTW this is a good read on htacces configuration: http://corz.org/serv/tricks/htaccess2.php

0

精彩评论

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