Cory Gwin
Cory Gwin

Reputation: 1243

Conditional URL rewrite?

I am trying to setup an htaccess redirect for the following situation.

If an app hits a URL containing /cms as the first segment http://originaldomain.com/cms I want to redirect to a secure domain https://differentdomain.com/cms.

If a URL hits https://differentdomain.com on any URL other then act, URL, system, or is a not a post then I want to redirect the user to http://originaldomain.com/requestedurl.

act is OK:

https://differentdomain.com/act?fiudsbsdfn=sfds

URL is OK:

https://differentdomain.com/url

system is OK:

https://differentdomain.com/system

POST methods are OK to any domain just redirect GET methods

Is this possible within an htaccess file?

Upvotes: 0

Views: 2298

Answers (1)

Prix
Prix

Reputation: 19528

Assuming both domains are on the same root folder and host:

RewriteCond %{HTTP_HOST} ^originaldomain\.com$
RewriteCond %{REQUEST_URI} ^/cms
RewriteRule ^(.*)$ https://differentdomain.com/$1 [L,R=302]

If they are not on the same root and folder:

RewriteCond %{REQUEST_URI} ^/cms
RewriteRule ^(.*)$ https://differentdomain.com/$1 [L,R=302]

Now the 2nd part if the url is not a act, url, system or post:

RewriteCond %{THE_REQUEST} !^[A-Z]{3,}\s/(act\?(.*)|url|system)$ [NC]
RewriteCond %{THE_REQUEST} !^POST [NC]
RewriteRule ^(.*)$ http://originaldomain.com/$1 [L,R=302]

Basically this should work, if it does after you test change to 302 to 301 if needed.

Upvotes: 2

Related Questions