Forum Topic: Remove .aspx from all incoming links

Forum: .htaccess Forum : Redirecting • Posted by Jeremy Hogan • Updated:

I have a lot of redirected incoming links. I would like to use htaccess to remove .aspx from any links that have them. I can't seem to find the answer in the book or the internet, but I'm probably missing something. I would appreciate any help.

3 Replies to “Remove .aspx from all incoming links”

Jeff Starr
Posted by Jeff Starr

Absolutely can help with that.. just let me know the structure of the URLs involved (to and from) using examples or whatever and I'll see what I can do.

Posted by Jeremy Hogan •

Sorry for the late reply. I thought I had responded to this, but there were apparently errors on my note.

I have a url like this /blogs/gsherman/archive/2010/09/21/information-regarding-the-recent-asp-net-security-vulnerability.aspx and I'm directing it to something like this /clarify/gsherman/2010/09/21/information-regarding-the-recent-asp-net-security-vulnerability/

I'm using this now (which works great for reordering the url, but does nothing for stripping the aspx)

RewriteCond %{QUERY_STRING} ^$
RewriteRule ^blogs/gsherman/$ /clarify/author/gsherman? [R=301,NE,NC,L]
Jeff Starr
Posted by Jeff Starr

The fact that the query strings are successfully targeted and redirected means that there is more going on behind the scenes..I'm guessing WP, Joomla, or similar is involved, and that particular rewrite works because it's getting at the requests before they are converted to permalinks. So, depending on how things go, that could be an important factor in getting it to work.

That said, without knowing anything about the QUERY_STRING method working, this looks like a straightforward redirect using either of these methods:

RedirectMatch 301 /blogs/gsherman/archive/(.*) http://example.com/clarify/gsherman/$1

..or:

<IfModule mod_rewrite.c>
	RewriteCond %{REQUEST_URI} /blogs/gsherman/archive/(.*) [NC]
	RewriteRule .* http://example.com/clarify/gsherman/%1 [R=301,L]
</IfModule>

These rules should work in the typical case, but again, it looks like there is more happening behind the scenes that may complicate things.