views:

124

answers:

3

I'm transferring an ASP.NET site to WordPress, and all my URLs are identical, except for the .aspx suffix.

Is there a one line regex htaccess solution that will forward people from

foo.com/bar/page.aspx

to

foo.com/bar/page

and

foo.com/bar.aspx

to

foo.com/bar

+1  A: 

Why do a regex?

That could be easily done just by doing a replace on the end with anything ending in ".aspx"

It's simpler and the string manipulation would be must faster than a regex match.

Regex is overkill in this situation, IMO.

I just did a quick search and found this article.

Basically you could do something like:

RewriteRule ^(.*)\.aspx$ $1 [NC]

That should remove aspx from any url that has it.

Joseph
So, how do you do that?
yankel
I edited my answer with a potential rule you could make in your htaccess.
Joseph
+2  A: 

No, not one-line .

Just a guess on my side here a.k.a. warning!, untested stuff ahead:

<IfModule mod_rewrite*>
# * = Your rewrite module may be named differently.
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} \.aspx$
    RewriteRule ^(.*)\.aspx$ $1
</IfModule>

But according to : http://wiki.apache.org/httpd/WhenNotToUseRewrite . it might be better expressed as :

RedirectMatch ^(.+)\.aspx$ $1

Hey, wait, that's one line... Now just hope that it works... :P If not, this might :

AliasMatch ^(.+)\.aspx$ $1

Sorry, not much of practical help at the moment, good luck.

immeëmosol
A: 

Hi all,

I'm trying to do the same thing and am running into issues. I need to redirect:

www.requirementsquest.com/Educate.aspx to //www.requirementsquest.com/training

I've tried this in my .htaccess but I get an "server error in application.." message. This is what I'm using:

Redirect 301 /Educate.aspx http://www.requirementsquest.com/training

Shouldn't this work?

Thanks, Jonah

Jonah