Map Directory to Query String Parameter
3 posts
• Page 1 of 1
Map Directory to Query String Parameter
I need help with a rule that maps the first directory into a query string parameter, but leaves my image and assets alone.
When I test the expression in the RegTest tool, it displays as I would expect. However, when executed on the actual server it says, "The page cannot be found"
My Complete file:
Here are some tests and how they should map.
sub.example.com/foo -> sub.example.com/default.aspx?page=foo
sub.example.com/bar -> sub.example.com/default.aspx?page=bar
sub.example.com/foo-bar -> sub.example.com/default.aspx?page=foo-bar
sub.example.com/images/logo.gif -> sub.example.com/images/logo.gif
When I test the expression in the RegTest tool, it displays as I would expect. However, when executed on the actual server it says, "The page cannot be found"
My Complete file:
- Code: Select all
# Helicon ISAPI_Rewrite configuration file
# Version 3.1.0.79
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule /(?!.*\.(?:gif|jpg|png|css|swf|link|script|js))(.+)/?([0-9]*)/? default.aspx?page=$1 [I,L]
Here are some tests and how they should map.
sub.example.com/foo -> sub.example.com/default.aspx?page=foo
sub.example.com/bar -> sub.example.com/default.aspx?page=bar
sub.example.com/foo-bar -> sub.example.com/default.aspx?page=foo-bar
sub.example.com/images/logo.gif -> sub.example.com/images/logo.gif
- HeliconAndrew
- Posts: 1264
- Joined: 07 Mar 2012, 10:16
Re: Map Directory to Query String Parameter
Hello,
I think the issue is pretty simple - a slash in front of the pattern. So all you need is:
However, I'd use:
Regards
I think the issue is pretty simple - a slash in front of the pattern. So all you need is:
- Code: Select all
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(?!.*\.(?:gif|jpg|png|css|swf|link|script|js))(.+)/?([0-9]*)/? default.aspx?page=$1 [I,L]
However, I'd use:
- Code: Select all
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^[^\.]\.(?:gif|jpg|png|css|swf|link|script|js) [NC]
RewriteRule ^([^/]+)/?.* /default.aspx?page=$1 [I,L]
Regards
Re: Map Directory to Query String Parameter
Thanks! I went with this one:
RewriteRule ^([^/]+)/?.* /default.aspx?page=$1 [I,L]
RewriteRule ^([^/]+)/?.* /default.aspx?page=$1 [I,L]
3 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 0 guests