Need some clarification on rules
6 posts
• Page 1 of 1
- lalitmishra1988
-
- Posts: 16
- Joined: 29 Apr 2013, 08:10
Need some clarification on rules
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]
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]
- HeliconAndrew
-
- Posts: 1264
- Joined: 07 Mar 2012, 10:16
Re: Need some clarification on rules
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:
Regards
Andrew
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
- lalitmishra1988
-
- Posts: 16
- Joined: 29 Apr 2013, 08:10
Re: Need some clarification on rules
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??
I have read somewhere that there might be some issue with images and CSS because of these type of rules....Is that right??
- HeliconAndrew
-
- Posts: 1264
- Joined: 07 Mar 2012, 10:16
Re: Need some clarification on rules
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
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
- lalitmishra1988
-
- Posts: 16
- Joined: 29 Apr 2013, 08:10
Re: Need some clarification on rules
Thanks, I got your point.
Can you have any solution to fix css and image issue?
Can you have any solution to fix css and image issue?
- HeliconAndrew
-
- Posts: 1264
- Joined: 07 Mar 2012, 10:16
Re: Need some clarification on rules
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:
Regards
Andrew
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
6 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 20 guests