Forum Moderators: phranque

Message Too Old, No Replies

rewrite for certain file extensions

         

bluehatdesign

12:55 am on Aug 15, 2012 (gmt 0)

10+ Year Member



We have redesigned our site and have switched from asp.net (umbraco) to Drupal. To complicate matters, we've changed the domain name.

The old domain name has a 301 redirect to the new domain name.

All of the old URLs have .aspx file extensions.
The new URLs all match, but without the file extensions, and using the new domain name.

example:
olddomain.com/file-name.aspx
newdomain.com/file-name

I'm not having success with the common rewrite rules for removing file extensions. I think it's because things are complicated due to the domain redirect.

When I enter an old URL with the .aspx file extension, the redirect adds the entire local path to the URL instead of starting at the web root.

Here is the rule I'm using:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.aspx -f
RewriteRule ^(.*)$ $1.aspx

How can I edit this to achieve the results I'm looking for?

Thanks!

g1smd

1:15 am on Aug 15, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



(assume .net is old site and .com is new site)

Your code says that when user asks for
example.net/some-page
that the server internally fetches
/some-page.aspx
to deliver the content. This is a rewite.

You need to configure RewriteRule as a redirect instead of a rewrite. That is, when user requests
example.net/some-page.aspx
the response is to tell them to make a new request for
example.com/some-page
instead.

RewriteRule can be configured as a rewrite or as a redirect. Make sure you fully understand the difference.

lucy24

6:01 am on Aug 16, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



when user requests example.net/some-page.aspx the response is to tell them to make a new request for example.com/some-page instead

Expanding this for people who aren't fluent in Apache ;)

"Make a new request" doesn't mean that the human user gets a message and has to type in a whole new URL. It means that the browser is told "Go around the back" and, in general, it quietly goes on to the new address. The human doesn't even notice unless you're looking right at the address bar.

That's why it is called a "User Agent". It acts on your behalf.