Help with Rewrite rules
9 posts
• Page 1 of 1
Help with Rewrite rules
These are my current rules.
What i want to do is add rules that appear before these rules that will rewrite http://www.website.com/aboutus.asp to http://www.website.com/aboutus
I also need http://www.website.com/category.asp?ID=119&page=1 to translate to http://www.website.com/Categoryname/page1
I need to add a few dozen similar rules and want the current rules above to run ONLY if none of the previous rules are matched.
I have tried several rules but they seem to either try to access a non-existent folder or try to run the rule that's already there after the correct rule, even if the last flag is set.
Any help would be greatly appreciated!
- Code: Select all
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)$ /item.asp?ID=$1 [NC,L]
RewriteCond %{QUERY_STRING} ^ID=([^&]+)$ [NC]
RewriteRule ^item\.asp$ /%1? [NC,R=301,L]
What i want to do is add rules that appear before these rules that will rewrite http://www.website.com/aboutus.asp to http://www.website.com/aboutus
I also need http://www.website.com/category.asp?ID=119&page=1 to translate to http://www.website.com/Categoryname/page1
I need to add a few dozen similar rules and want the current rules above to run ONLY if none of the previous rules are matched.
I have tried several rules but they seem to either try to access a non-existent folder or try to run the rule that's already there after the correct rule, even if the last flag is set.
Any help would be greatly appreciated!
- HeliconAndrew
- Posts: 1264
- Joined: 07 Mar 2012, 10:16
Re: Help with Rewrite rules
Hello,
a) rules are processed in the order they appear in config file
b) your check for realness might not work because of the permissions to the folder. Those require NTFS permissions to ListFolderContent.
You may want to turn on logging and see how the rules are processed.
Logging issues described in FAQ
Regards
Andrew
a) rules are processed in the order they appear in config file
b) your check for realness might not work because of the permissions to the folder. Those require NTFS permissions to ListFolderContent.
You may want to turn on logging and see how the rules are processed.
Logging issues described in FAQ
Regards
Andrew
Re: Help with Rewrite rules
I changed the rewrite to work without the folder issue according to the logs, but on the redirect it is also getting caught in the overall rule
RewriteRule ^([^/]+)$ /item.asp?ID=$1 [NC,L]
Is there a way to exclude that rule on the redirect? I only want that rule active if none of the other rules above were valid at any point.
/Contact.asp is rewritten to /contact, then /contact matches the rule above and redirects to item.asp?id=contact which is NOT the desired behavior.
The rule above is for website.com/X1234 where X1234 is the item number... All of the item numbers follow the format X and 4 digits.
Any suggestions, when i try to change the overall rule to look for X then wildcard it goes into infinite redirect loop.
RewriteRule ^([^/]+)$ /item.asp?ID=$1 [NC,L]
Is there a way to exclude that rule on the redirect? I only want that rule active if none of the other rules above were valid at any point.
/Contact.asp is rewritten to /contact, then /contact matches the rule above and redirects to item.asp?id=contact which is NOT the desired behavior.
The rule above is for website.com/X1234 where X1234 is the item number... All of the item numbers follow the format X and 4 digits.
Any suggestions, when i try to change the overall rule to look for X then wildcard it goes into infinite redirect loop.
- HeliconAndrew
- Posts: 1264
- Joined: 07 Mar 2012, 10:16
Re: Help with Rewrite rules
Here's a regular expression for a string starting with a letter and followed by 4 digits.
Regards
Andrew
- Code: Select all
RewriteRule ^([A-Za-z]\d{4})$ /item.asp?ID=$1 [NC,L]
Regards
Andrew
Re: Help with Rewrite rules
I seem to be having an inordinate amount of trouble getting even the simplest thing to work. Does your company offer a service where they can write up the rules for us based on a list of requirements that i can email you.
Using the code you gave me above to modify my original rules, it goes into an infinite redirect loop as well.
Using the code you gave me above to modify my original rules, it goes into an infinite redirect loop as well.
- Code: Select all
RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([A-Za-z]\d{4})$ /item.asp?ID=$1 [NC,L]
RewriteCond %{QUERY_STRING} ^ID=([A-Za-z]\d{4})$ [NC]
RewriteRule ^item\.asp$ /%1? [NC,R=301,L]
- HeliconAndrew
- Posts: 1264
- Joined: 07 Mar 2012, 10:16
Re: Help with Rewrite rules
Hi,
a) Yes, we have Premium Support Plan where we do everything for you, using online meeting, skype or RDP. Simply go to Support tab on top of the site.
b) I suspect you have other rules taking part in it. to make sure it's not these 2 I'd use NS flag to make sure no other subrequest is running after the first rule:
Regards
Andrew
a) Yes, we have Premium Support Plan where we do everything for you, using online meeting, skype or RDP. Simply go to Support tab on top of the site.
b) I suspect you have other rules taking part in it. to make sure it's not these 2 I'd use NS flag to make sure no other subrequest is running after the first rule:
- Code: Select all
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([A-Za-z]\d{4})$ /item.asp?ID=$1 [NC,L,NS]
RewriteCond %{QUERY_STRING} ^ID=([A-Za-z]\d{4})$ [NC]
RewriteRule ^item\.asp$ /%1? [NC,R=301,NS,L]
Regards
Andrew
Re: Help with Rewrite rules
Log info
Complete Rules File
has a dozen or so entries in the log per page load, just keeps repeating itself until page times out.
I will take a look at the Support tab.
- Code: Select all
(2) init rewrite engine with requested uri /X1502
(1) Htaccess process request C:\Program Files\Helicon\ISAPI_Rewrite3\httpd.conf
(1) Htaccess process request c:\inetpub\website\.htaccess
(3) applying pattern '^([A-Za-z]\d{4})$' to uri 'X1502'
(4) RewriteCond: input='C:\inetpub\website\X1502' pattern='!-f' => matched
(4) RewriteCond: input='C:\inetpub\website\X1502' pattern='!-d' => matched
(1) Rewrite URL to >> /item.asp?ID=X1502
(2) rewrite 'X1502' -> '/item.asp?ID=X1502'
(2) internal redirect with /item.asp?ID=X1502 [INTERNAL REDIRECT]
(2) init rewrite engine with requested uri /item.asp?ID=X1502
(1) Htaccess process request C:\Program Files\Helicon\ISAPI_Rewrite3\httpd.conf
(1) Htaccess process request c:\inetpub\website\.htaccess
(3) applying pattern '^([A-Za-z]\d{4})$' to uri 'item.asp'
(3) applying pattern '^item\.asp$' to uri 'item.asp'
(4) RewriteCond: input='ID=X1502' pattern='^ID=([A-Za-z]\d{4})$' => matched
(1) escaping /X1502
(2) explicitly forcing redirect with http://www.website.com/X1502
(2) internal redirect with /item.asp?ID=X1502 [INTERNAL REDIRECT]
Complete Rules File
- Code: Select all
# Helicon ISAPI_Rewrite configuration file
# Version 3.1.0.89
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([A-Za-z]\d{4})$ /item.asp?ID=$1 [NC,L,NS]
RewriteCond %{QUERY_STRING} ^ID=([A-Za-z]\d{4})$ [NC]
RewriteRule ^item\.asp$ /%1? [NC,R=301,NS,L]
has a dozen or so entries in the log per page load, just keeps repeating itself until page times out.
I will take a look at the Support tab.
Re: Help with Rewrite rules
That took care or the redirect loop! Will now try adding back the other rules, thanks!
9 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 0 guests