pszafer
pszafer

Reputation: 388

.htaccess redirect main domain and not subdomain

I have domains mydomain.co and mydomain.com In mydomain.co I want to install YOURLS.

It is working very well, but I want to create such redirect.

example.org -> R301 -> example.com

example.org/* -> /yourls-loader.php

I have something like this, but it is not working :(

<IfModule mod_rewrite.c>                                                                                                                                                                                           
RewriteEngine On                                                                                                                                                                                                   
RewriteCond %{HTTP_HOST} ^(www.)?example.org                                                                                                                                                                          
RewriteRule ^$ http://example.com [L,R=301]                                                                                                                                                                     
#RewriteBase /                                                                                                                                                                                                     
RewriteCond %{REQUEST_FILENAME} !-f                                                                                                                                                                                
RewriteCond %{REQUEST_FILENAME} !-d                                                                                                                                                                                
RewriteRule ^.*$ /yourls-loader.php [L]                                                                                                                                                                            
</IfModule>

How should .htaccess file look for my configuration?

Upvotes: 0

Views: 818

Answers (2)

pszafer
pszafer

Reputation: 388

Finally, I've got it working.

<IfModule mod_rewrite.c>
  RewriteEngine on
  RewriteBase /
  RewriteCond %{HTTP_HOST} ^(www.)?example.org [NC]
  RewriteCond %{REQUEST_URI} ^/(.+)$
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_URI} !^/admin
  RewriteRule ^(.*)$ /yourls-loader.php [L]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_URI} !^/admin
  RewriteRule ^(.*)$ http://example.com [R=301,L]
</IfModule>

Upvotes: 1

Raphael M&#252;ller
Raphael M&#252;ller

Reputation: 2200

you can simply use:

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

and everything that has a subdomain gets redirected to the one without. the rest stays the same.

Upvotes: 0

Related Questions