Rule to rewrite folder, using part of the domain.

ISAPI_Rewrite is Apache mod_rewrite compatible URL rewriter for Microsoft IIS
User avatar
Posts: 2
Joined: 20 Jul 2016, 05:48

Rule to rewrite folder, using part of the domain.

20 Jul 2016, 05:53

I am having trouble putting this rule together:

I need to match part of the domain and redirect specific folders to another domain using the captured part.

Ideally it should also work if the www is not specified, but that's not essential.

eg.
www.mysite.com/a/ --> media.mysite.com/x/a
mysite.com/a/ --> media.mysite.com/x/a

The catch is I don't want to put the domain into the rule, (eg. the "mysite" part) as it has to match for any site on the server. However they are all .com domains.

Any help appreciated!

Thanks

User avatar
Posts: 402
Joined: 06 Mar 2012, 11:59

Re: Rule to rewrite folder, using part of the domain.

24 Jul 2016, 08:21

Hello.

Sorry, it is unclear from your explanation where exactly you need to match a domain and how to redirect it.
From your example it seems like you need to redirect everything in folder /a/ (where? in mysite.com or on any site?) to media.mysite.com/x/a*

User avatar
Posts: 2
Joined: 20 Jul 2016, 05:48

Re: Rule to rewrite folder, using part of the domain.

25 Jul 2016, 03:01

Sorry I was unclear.

I want to rewrite everything in the /a folder in www.mysite.com to the same path in media.mysite.com but with a /x/ at the start of the path. It should happen for all sites.

eg.
www.mysite.com/a/1234/567/89.jpg --> media.mysite.com/x/a/1234/567/89.jpg
www.mysecondsite.com/a/1234/567/89.jpg --> media.mysecondsite.com/x/a/1234/567/89.jpg

Thank you.

User avatar
Posts: 402
Joined: 06 Mar 2012, 11:59

Re: Rule to rewrite folder, using part of the domain.

27 Jul 2016, 08:10

I suppose you actually need a redirect, not rewrite. Please try this:

RewriteEngine On

RewriteCond %{HTTP_HOST} (?:www\.)?mysite\.com [NC]
RewriteRule (/a.*) http\://media.mysite.com/x$1 [NC, QSA, R]

Return to ISAPI_Rewrite 3.0

Who is online

Users browsing this forum: No registered users and 6 guests