views:

12

answers:

1

We just redesigned a site for a client in EE, located at example.com (with and without www.). Their original site is ASPX. They've still got a number of ASPX pages that they want to keep, so their IT people created a subdomain, www2, which is basically a clone of their old site.

I need an htaccess rule that will check if the requested page ends in .aspx, then redirects to the www2 subdomain. It should also make sure that the requested page doesn't exist

I tried using the following rule, but it doesn't work.

RewriteRule ^http://[www\.?]example.com/(.*)\.aspx$ http://www2.example.com/$1 [R=301,L]

My htaccess file (including the above rule) looks like this:

RewriteEngine On

# redirect all .aspx pages to www2
RewriteRule ^http://[www\.?]example.com/(.*)\.aspx$ http://www2.example.com/$1 [R=301,L]

# strip index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]

Does anyone have a solution for this?

A: 

The RewriteRule directive does only test the URL path. If you want to test any other part of the requested URL, you need to use the RewriteCond directive:

RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$
RewriteRule ^(.*)\.aspx$ http://www2.example.com/$1 [R=301,L]
Gumbo
This worked perfectly, thanks!
Jazzerus
Actually, there's one problem with this solution: it strips the .aspx off the URL. I fixed by adding .aspx after $1
Jazzerus
@Jazzerus: You could also use this rule instead: `RewriteRule ^.+\.aspx$ http://www2.example.com/$0 [R=301,L]`
Gumbo