htaccess: redirect old asp url strings - .htaccess

I have a client we built a new site for and are trying to redirect his old urls to point to the new site. The problem is they are long strings and my current solution is not working correctly. This is what I currently have:
Redirect 301 /frameset.asp?page=services.htm http://domain.com/
this results in the user being sent to:
http://domain.com/.asp?page=services.htm
Last but not least is there a wildcard solution?
FROM THE ACCEPTED ANSWER: (Just so this is documented for the next guy, yhis is what i ended up using.
RewriteEngine on
RewriteCond %{THE_REQUEST} /frameset\.asp\?page=* [NC]
RewriteRule ^ http://domain.com/? [L,R]

You can not redirect query strings using a Redirect directiv, you have to use mod-rewrite
Try :
RewriteEngine on
RewriteCond %{THE_REQUEST} /frameset\.asp\?page=services\.html [NC]
RewriteRule ^ http://domain.com/? [L,R]

Related

htaccess redirect url not working /?index.html to /

I have a client project on search engine marketing with a website https://www.iehsacademy.com/,
The site is 13 years old. before the client was using the URL structure like with HTML like this: https://www.example.com/?index.html (Home Page),
https://www.example.com/?cndc.html,
But last year they completely remake the website URL structure and make it to https://www.example.com/ (Home Page), https://www.exsample.com/about. https://www.example.com/contact.
Now, The old URLs and the new URLs are both working. The client wants and also for SEO purposes we want to block the old URL or redirect them to the new URL. I tried many rewrite conditions on htaccess
RewriteRule ^([a-z]+).html https://www.iehsacademy.com/ [QSA,L]
This one also
RewriteCond %{HTTP_HOST} ^www.iehsacademy.com/?cndc.html$
RewriteRule (.*)$ http://www.iehsacademy.com/$1 [R=301,L]
Not Working anything. The client's developer is also confused. Can anyone help with this or where i am doing wrong?
NB: I took permission from the site owner to share the client's URLs and problems.
You can use the following redirection rule :
RewriteEngine On
#redirect /?index.html to /
RewriteCond %{HTTP_HOST} ^www.iehsacademy.com$ [NC]
RewriteCond %{QUERY_STRING} ^index\.html$
RewriteRule ^$ https://example.com/? [L,R=301]
#redirect /?foobar to /foobar
RewriteCond %{HTTP_HOST} ^www.iehsacademy.com$ [NC]
RewriteCond %{QUERY_STRING} ^(.+)$
RewriteRule ^$ https://example.com/%1? [L,R=301]
Make sure to clear your browser caches or use a different browser to test the redirection. And do not forget to replace the destination domain example.com with your domain name.

RewriteEngine - forcing new friendly URLs causes too many redirections

This rule translates URLs like
http://www.example.com/index.php?page=about to friendly URLs like http://www.example.com/about
RewriteRule ^([a-zA-Z_]+)?$ index.php?page=$1 [NC,L]
It's working well. But, currently old URLs (like http://www.example.com/index.php?page=about) are indexed in google. So, in addition to that rule I need to redirect all old URLs (like http://www.example.com/index.php?page=about) to new friendly URLs (like http://www,example.com/about) so when visitor old URL he gets redirected to friendly URL. I wrote that rule:
RewriteCond %{QUERY_STRING} ^page=([^&]+)$ [NC]
RewriteRule ^index\.php$ http://www.example.pl/%1? [NC,R=301,L]
and it redirects to new URL but instead of showing a website content, it throws an error ERR_TOO_MANY_REDIRECTS.
Any help?
You are getting too many redirect error because of your internal rewriteRules,as they internaly forward the request to the same location after first rewrite iteration, to fix this , add the following at top of your htaccess,
RewriteEngine on
RewriteCond %{ENV_REDIRECT_STATUS} 200
RewriteRule ^ - [L]
or you can match against %{THE_REQUEST} instead of %{QUERY_STRING} to avoid rewrite loop/too many redirect error
RewriteCond %{THE_REQUEST} /index\.php\?page=([^\s]+) [NC]

Redirect to another website using wordpress and querystring

I am new to WordPress and want to redirect some specific traffic. Here's an example -
A user from a different website clicks on a link with url http://mywordpresssite.com/redirect?url=http://amazon.in/blablabla
I want my website to redirect the request to
http://amazon.in/blablabla or whatever be the url in the querystring without loading anypage of my website.
My website should function normally for all other requests.
I tried with htaccess and came up with this -
RewriteCond %{QUERY_STRING} (?:^|&)url=([^&]+)(?:&|$) [NC]
RewriteRule ^(.*)$ %1 [R=302,L]
But the RewriteRule results in http://mywordpresssite.com/http://amazon.in/blablabla?url=http://amazon.in/blablabla which is wrong.
I am new to htaccess and would be grateful for any help.
Try the following in .htaccess in the root of your site. Note that this should go before your existing WordPress mod_rewrite rules but after RewriteEngine On.
RewriteCond %{QUERY_STRING} ^url=(.*)$
RewriteRule ^redirect$ %1 [R=302,QSD,L]
The %1 refers to the first parenthesised subpattern in the RewriteCond directive (ie. everything after the "url=").
The QSD flag (Apache 2.4+) removes the query string from the original request.
Before Apache 2.4 you would need to change the RewriteRule to read (note the additional ? at the end of the substitution):
RewriteRule ^redirect$ %1? [R=302,L]

htaccess mod rewrite not redirecting automatically

I have the below code in my htaccess file:
RewriteCond %{REQUEST_URI} !\.(gif|css|png|js|jpg|jpeg|html)$ [NC]
RewriteCond %{REQUEST_URI} !(\.gif|\.jpg|\.png)$ [NC]
RewriteRule ^deals/(.+)/(.+)/$ deals.php?make=$1&model=$2 [L,QSA]
This means I have SEO friendly urls - rather than going to:
URL.com/deals?make=Samsung&model=500CC (Old SEO unfriendly URL)
I can use:
URL.com/deals/Samsung/500CC/
The issue I have is if a user has bookmarked one of my old urls, it does not automatically redirect them to the new style. I have tried adding R=301 but that takes users from the new url to the old.
I've then tried switching them around with the R-301 in place but that still does not work for me.
Appreciate if somebody can help me get any hits to my old url, redirected to the new SEO friendly structure.
You can have another rule to redirect old URL to new one:
RewriteEngine On
RewriteCond %{THE_REQUEST} \s/+deals(?:\.php)?\?make=([^\s&]+)&model=([^\s&]+) [NC]
RewriteRule ^ /deals/%1/%2? [R=302,L]
RewriteCond %{REQUEST_URI} !\.(gif|css|png|js|jpg|jpeg|html)$ [NC]
RewriteRule ^deals/(.+)/(.+)/$ deals.php?make=$1&model=$2 [L,QSA]

301 redirecting pagination with get variables

I'm trying to set 301 redirects on pages that have 'page=1' in the URL to stop duplicate content issues.
e.g.
http://www.domain.com/reviews/?page=1
to
http://www.domain.com/reviews/
I've tried all of the variations I can find and can't seem to get anything to work.
RewriteRule ^reviews(/)?page=1$ http://www.domain.com/reviews/ [L,R=301]
RewriteRule ^(.*)/?page=1 http://www.domain.com/reviews/ [R=301,L]
RewriteCond %{QUERY_STRING} page=1
RewriteRule ^reviews$ http://www.domain.com/reviews/ [R=301,L,NE]
None of these have worked. I'm not really sure what else to try.
There are multiple different sections of the site that I need to do this for:
reviews
news
videos
accessories
hardware
An overall solution to redirect all ?page=1 URLs to their relevant section would be best.
Use this code to redirect every URI with ?page=1 to one without the query parameter:
RewriteCond %{QUERY_STRING} ^page=1(&|$) [NC]
RewriteRule ^ %{REQUEST_URI}? [R=301,L]
Or else if you want to redirect ONLY /reviews URI then
RewriteCond %{QUERY_STRING} ^page=1(&|$) [NC]
RewriteRule ^(reviews)/?$ /$1? [R=301,L]
the question is already answered, i just would like to mention that your rules are not working because you didn't append a trailing ? to the new url in the rewrite rule

Resources