Rebuilt an existing site:

Old site used aspx pages, for example:
(broken)

New site is in Joomla; new link is:
http://americascarshow.com/gadgetcentral

I tried a 301 redirect in .htaccess file but cld not get it to work.

I need a solution to redirect links to new pages and/or at least get them to redirect to the site's homepage.

Thanks in advance for any help!

Dani AI

Generated

Short answer: the simple Redirect directive only matches the path portion of the request and does not see anything after the ?. As guessed, you need mod_rewrite (regex) to inspect the query string. Below are small, practical options you can drop into the site root .htaccess on your Apache server and test.

Example — redirect that specific old Detail.aspx request to the new Joomla path (permanent 301):

RewriteEngine On

# Detail.aspx?dct=11&mid=1656  ->  /gadgetcentral
RewriteCond %{QUERY_STRING} (?:^|&)dct=11(?:&|$) [NC]
RewriteCond %{QUERY_STRING} (?:^|&)mid=1656(?:&|$) [NC]
RewriteRule ^Detail\.aspx$ /gadgetcentral? [R=301,L]

Notes: each RewriteCond checks the query-string (order doesn’t matter); the trailing ? in the substitution strips the old query string. On Apache 2.4+ you can use the [QSD] flag instead of the ?.

If you just want a simple catch-all that sends any .aspx request that carries a query string to the homepage (useful as a fallback):

# any .aspx with a querystring -> homepage (drop qs)
RewriteCond %{REQUEST_URI} \.aspx$ [NC]
RewriteCond %{QUERY_STRING} .
RewriteRule ^ /? [R=301,L]

If you have many old mid → new-slug mappings, maintain a small lookup script instead of dozens of rewrite rules. Example flow: rewrite Detail.aspx internally to redirect-old.php, have that PHP read dct/mid from $_GET, consult an array or DB and issue a header("Location: /new-slug", true, 301). This is easier to maintain than a long list of .htaccess rules.

Troubleshooting: enable mod_rewrite and AllowOverride, test with curl -I (avoids browser 301 caching), use temporary 302 while testing, clear browser cache, and use Google Search Console to request re-crawl after you’ve verified redirects. — the working Redirect for plain /Home.aspx is expected; the rules above will handle the query-string cases that were failing.

Recommended Answers

All 5 Replies

Member Avatar for Member #120589

.htaccess on a windows server? You running Apache or IIS? If IIS, .htaccess won't work - well not without a lot of messing about. IIS should have its own way of providing a 301, but can't help with that as I know v. little about IIS.

No. The new server is Apache. The old server was IIS. That is part of the problem.

Member Avatar for Member #120589

Yeah, that's what I was referring to - the old server. How about this:

My apologies for not explaining the situation more fully.

The old server (IIS) is no longer. But the aspx links that it used still "live" in Google and I wld like to redirect those aspx links to the new (Apache) server site.

I have had limited success using a 301 redirect in .htaccess; for example:

Redirect 301 /Home.aspx

Works fine. But the example that I opened the post with:

Redirect 301 /Detail.aspx?dct=11&mid=1656

Does not work nor does any link that has a "?" after the aspx.

So I need a solution to redirect broken links that use the old aspx? nomenclature to the new pages at the site.

Member Avatar for Member #120589

Ah, I see, you need a regex (wo)man. I'm a complete numpty at regex - anybody else out there?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.