Question

A really easy one, but I need to get this right, and cannot afford mistakes as I need to deploy on a live server as soon as I can.

http://www.foo.com/bar --> http://www.foo.com/bar.aspx
http://www.foo.com/bar?q=boo --> http://www.foo.com/bar.aspx?q=boo

# I only want /bar to get rewritten to /bar.aspx
# everything else stays as is
http://www.foo.com/bar.aspx --> http://www.foo.com/bar.aspx
http://www.foo.com/bar.pdf --> http://www.foo.com/bar.pdf  

I got here, but this turns bar.aspx into bar.aspx.aspx, and that ain't good.

# Helicon ISAPI_Rewrite configuration file

RewriteEngine on
RewriteRule (.*) $1.aspx [L]
Was it helpful?

Solution

Try this rule:

RewriteCond $1 !.*\.aspx$
RewriteRule (.*) $1.aspx [L]

That should avoid any possible problems with recursion. And if you want to exclude already existing files, try this condition instead:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*) $1.aspx [L]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top