Reputation: 63
I've redesigned a website (former windows/asp) and the new website runs on wordpress.
So I wanted to do 301 Redirects on all old links, but somehow this isn't working and I'm new to .htaccess redirects.
Redirect 301 /index.asp http://balbla.com/#work
Redirect 301 /index.asp?ID=177 http://blabla.com/portfolio/blablatitle/
It seems all behind "?" gets ignored. Because blabla.com/index.asp?ID=177
redirects now to http://balbla.com/#work?ID=177
Can anyone help me?
So these are the different pattern types of the urls, each of them should redirect to a different page:
Mainpages:
/index.asp?inc=index.asp&typ=Nav1&cat=2
/index.asp?inc=index.asp&typ=Nav1&cat=3
...
Portfolio-Pages:
/?inc=index.asp&ID=5
/?inc=index.asp&ID=24
/?inc=index.asp&ID=147
Subpages:
/index.asp?inc=agentur/advertising.asp
/index.asp?inc=agentur/design.asp
/index.asp?inc=agentur/dialog.asp
Upvotes: 2
Views: 166
Reputation: 45829
In addition to the following question/answer which discusses WordPress and mod_rewrite:
.htaccess 301 redirect not working?
In order to match against the query string, you'll need to use mod_rewrite and test against QUERY_STRING
in a condition. For example:
RewriteEngine On
RewriteCond %{QUERY_STRING} =ID=177
RewriteRule ^index\.asp$ http://blabla.com/portfolio/blablatitle/ [R=301,L]
The RewriteRule
pattern (ie. ^index\.asp$
) matches against the URL-path only and notably excludes the slash prefix in per-directory .htaccess files.
Note that the CondPattern above (ie. =ID=177
) uses the =
operator so is a simple string comparison (as opposed to a regex).
The more specific redirects will need to appear first, with the most general (catch-all) redirects last.
As mentioned in comments, to make this more general and redirect all URLs that are of the form /index.asp?inc=index.asp&ID=NNN
, where NNN
is any 3 digits, to a single URL then you can do something like:
RewriteCond %{QUERY_STRING} ^inc=index\.asp&ID=\d\d\d$
RewriteRule ^index\.asp$ http://blabla.com/portfolio/blablatitle/ [R=301,L]
Upvotes: 1