Question

I'm very new to Apache and already run into an problem which already takes a lot of time and I'm not even sure if it's possible.

I have two servers and one Domain called szop.in which is having an A record to my first server. On the first server I'm running an URL shortener called YOURLS, it's under szop.in/admin. I want the second server serve my homepage, therefor I want to redirect all requests like szop.in or http://subdomain.szop.in to the second server but not http://szop.in/admin.

Is this possible?

This doesn't seem to be the right solution and the mod_rewrite is causing me some headache:

RewriteEngine On
RewriteCond %{HTTP_HOST} szop.in [NC]
RewriteRule !^/admin$ hxxp://other-domain.in [R=301,L]

My idea was, since I need just one URL to work on the first server http://szop.in/admin, to redirect everything that is not starting with /admin to the other domain.

Was it helpful?

Solution

You almost got it:

Options +FollowSymLinks -MultiViews

RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} ^szop\.in$ [NC]
RewriteCond %{REQUEST_URI} !^/admin [NC]
RewriteRule ^ http://subdomain.szop.in%{REQUEST_URI} [R=301,L]

You cannot use the negation on the RewriteRule like that, you use it on a conditions.

This should do what you want, it verify if domain is szop.in and if folder is not /admin and redirect to subdomain.szop.in.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top