Need some clarification on rules

ISAPI_Rewrite is Apache mod_rewrite compatible URL rewriter for Microsoft IIS
User avatar
Posts: 16
Joined: 29 Apr 2013, 08:10

Need some clarification on rules

20 Jul 2013, 18:09

Hi,

I have some scenarios:

1. If any URL contains Host name like "https://a.s.com" then it should redirects to the particular page.
2. If any URL contains string like "https://a.s.com/Test" then it should redirects to the particular page.
3. If any URL contains string like "https://a.s.com/Test/Test1" then it should redirects to the particular page.

I have written some rules for this scenarios and I want to confirm that these are valid or not and is there any other better approach to write these rules ??

1. RewriteCond %{HTTP:Host} ^a\.s\.com$ [NC]
RewriteRule ^(.*)$ https://a.s.com/default.aspx [NC,R=301,L,NE]

2. RewriteCond %{HTTP:Host} ^a\.s\.com$ [NC]
RewriteRule ^([^/]*)/(.*)$ https://a.s.com/default.aspx [NC,R=301,L,NE]

3. RewriteCond %{HTTP:Host} ^a\.s\.com$ [NC]
RewriteRule ^([^/]*)/([^/]*)/(.*)$ https://a.s.com/default.aspx [NC,R=301,L,NE]

User avatar
Posts: 1264
Joined: 07 Mar 2012, 10:16

Re: Need some clarification on rules

21 Jul 2013, 22:57

Hello,

The first rule will be the only one that work. It'll match all types of URLs.
Your options:

A) reverse the order of the rules. you need to start with the narrowest and end with the most generic.
B) change the rules to be more specific in patterns

You may want want to use the following conditions:

Code: Select all
RewriteCond %{HTTPS} on


Regards
Andrew

User avatar
Posts: 16
Joined: 29 Apr 2013, 08:10

Re: Need some clarification on rules

22 Jul 2013, 00:32

so that means, all rules which I have mentioned are right? what do you mean by point "B".

I have read somewhere that there might be some issue with images and CSS because of these type of rules....Is that right??

User avatar
Posts: 1264
Joined: 07 Mar 2012, 10:16

Re: Need some clarification on rules

22 Jul 2013, 08:44

I assumed that all 3 rules will be used in the same config file. In this case the first one will be the only one that works, because (.*) matches everything. simply the second and the third rule won't be executed. The same with the rule #2 compared to rule #3. The rule #2 has more generic pattern and will match the URLs that rule #3 matches.

I suggest using more narrow pattern for these rules, for example, ^folderName/(.*)$. Depends on your URl structure.

The problems with .css and images may occur of the links to css and images are relative. You need to have the links in absolute or root-relative format.

Regards
Andrew

User avatar
Posts: 16
Joined: 29 Apr 2013, 08:10

Re: Need some clarification on rules

22 Jul 2013, 15:39

Thanks, I got your point.

Can you have any solution to fix css and image issue?

User avatar
Posts: 1264
Joined: 07 Mar 2012, 10:16

Re: Need some clarification on rules

22 Jul 2013, 17:11

Solution is to change all the links on all the pages(some CMS offer this option).

There's also a workaround that may work. You need to exclude .css and other images files from rewriting:

Code: Select all
RewriteCond %{REQUEST_URI} !^[^\.]+\.(?:css|jpg|gif)
RewriteRule .* - [NC,L]


Regards
Andrew

Return to ISAPI_Rewrite 3.0

Who is online

Users browsing this forum: No registered users and 20 guests