.htaccess 301 redirect with query - .htaccess

I know there are tons of these questions out there, but I still don't understand my issue. Thanks to a miscellaneous link found on Google, we've found a bad link for this website. I wrote a rewrite condition for it that is the below:
RewriteCond %{QUERY_STRING} ^t=&s=BARREEL+YOUR+OWN+BOURBON+RISKY+WHISKY+BARREL+PACK+$
RewriteRule ^/results.php$ http://www.thepartysource.com/express/item.php?id=28952 [R=301]
The '+' are in the actual link. I've tried writing it as follows so that it doesn't count them as special characters:
RewriteCond %{QUERY_STRING} ^t=&s=BARREEL\+YOUR\+OWN\+BOURBON\+RISKY\+WHISKY\+BARREL\+PACK\+$
RewriteRule ^/results.php$ http://www.thepartysource.com/express/item.php?id=28952 [R=301]
The site still takes me to the wrong page and does not redirect me. Can someone help with this please? Thanks in advance.
EDIT:
The URL is
/results.php?t=&s=BARREEL+YOUR+OWN+BOURBON+RISKY+WHISKY+BARREL+PACK+

Rather than getting out RewriteRules you can use Redirect instead
Redirect 301 /results.php?t=&s=BARREEL+YOUR+OWN+BOURBON+RISKY+WHISKY+BARREL+PACK+ http://www.thepartysource.com/express/item.php?id=28952 [R=301]
However, it's worth noting, that Google has said you should Disallow/no-index search result pages on your site.

Related

Redirect Specific non-existing URL to an existing

I have a simple need to redirect:
mypage.com/myurl (which doesn't not exist; meening that returns a 404 error)
To
mypage.com/newurl/myurl (which is an exitsing page with content).
I saw a tons of forum post about this, but didn't find an awnser. I tried lot of thinks but with internal server error, infinitive loops etc.
Please note that I have a www to non www permanent redirect, like this:
RewriteCond %{HTTP_HOST} ^www\.mypage\.si [NC]
RewriteRule ^(.*)$ http://mypage.si/$1 [L,R=301]
UPDATE:
I will be specific:
This URL doesn't exist: http://domodom.si/sl/nepremicnine
and needs to be redirected here: http://domodom.si/sl/nepremicnine/nepremicnine-ponudba
Hope this will offer more insights about the problem.
Thanks
assuming mod_rewrite
RedirectPermanent /myurl/ mypage.com/newurl/myurl
Add this to your .htaccess file
RewriteBase /
RewriteRule ^(.*)$ newurl/$1 [NC,L]
you may want to try implementing the answer of nwellnhof in this thread.. it worked for me..

htaccess redirect trouble

I use mod-rewrite and I do this:
RewriteRule ^brand/([A-Za-z0-9-]+)/([A-Za-z0-9-\.\_]+)/?$ model.php?ref=$2&brand=$1 [NC]
and it works great! But I have a problem: when you go by url like
brand/stuff/ffgfgfgfg.php it will redirect to a page brand/stuff/ffgfgfgfg?ref=ffgfgfgfg.php&brand=stuff. I want to get rid of such a situation as it is not very good for the promotion on Google.
Maybe anyone can help me out and suggest a solution to redirect that awkward page?
Well here are your options. If, as you say in your comment (although I find it a bit strange) you want to redirect brand/stuff/ffgfgfgfg.php to brand/stuff/ffgfgfgfg, you can use
RewriteRule ^brand/([A-Za-z0-9-]+)/([A-Za-z0-9-\.\_]+).php/?$ brand/$1/$2 [NC]
Apparently, if you want to redirect to brand/stuff/ffgfgfgfg?ref=ffgfgfgfg&brand=stuff, you could use
RewriteRule ^brand/([A-Za-z0-9-]+)/([A-Za-z0-9-\.\_]+).php/?$ model.php?ref=$2&brand=$1 [NC]

.htaccess redirect all directories and subdomains to http://domain.com/

I've scoured Google and stackoverflow for a solution to this problem. Hopefully somebody here can help. I have an old website that I am no longer using. I would like all requests 301 redirected to http://example.com/ using .htaccess. That includes requestas such as:
- http://whatever.example.com/
- http://example.com/whatever
- http://whatever.example.com/whatever
I have tried a few ideas I found online, but either they won't redirect both subdomains and directories, or they result in infinite loops.
Thanks,
Mike
Thanks for the help #Virendra.
This is what I have now, and it works. The first condition and rule make sure the file being requested isn't /robots.txt and then 301 to http://socialenigma.com/. The second condition and rule check that the host is socialenigma.com (without any subdomain) and, if not, 301 to http://socialenigma.com/.
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/(robots\.txt).*$
RewriteRule . http://socialenigma\.com/ [R=301,L]
RewriteCond %{HTTP_HOST} !^socialenigma\.com$
RewriteRule (.*) http://socialenigma\.com/$1 [R=301,L]
It seems that this isn't as efficient as it could be. Maybe someone can help condense these rules.

301 redirect htaccess on a database driven website

I have created a website using IPB which I believe is written in PHP.
i am trying to use a 301 prominent redirect but when ever I try to use any from around the web I get a 500 server error
the broken url is 'http://thereviewforum.com/index.php?/page/index.html/_/monthly-top-10/top-10-free-vpn-service-providers-r17'
and I would like to direct users and search bots to
http://thereviewforum.com/monthly_top_10.html/_/monthly-top-10/top-10-free-vpn-service-providers-r17
again any help with be greatly appreciated!
I think you can do (The following does not work. See below for working example):
Redirect 301 /index.php?/page/index.html/_/monthly-top-10/top-10-free-vpn-service-providers-r17 http://thereviewforum.com/monthly_top_10.html/_/monthly-top-10/top-10-free-vpn-service-providers-r17
Edit:
You are right the above does not work. I guess query strings aren't considered. I should have tested it first. Here is an example that I tested to make sure it worked.
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/index.php$
RewriteCond %{QUERY_STRING} ^/page/index.html/_/monthly-top-10/top-10-free-vpn-service-providers-r17$
RewriteRule .? /monthly_top_10.html/_/monthly-top-10/top-10-free-vpn-service-providers-r17 [L,R=301]

How to redirect using .htaccess using Apache?

Please help me to redirect using .htaccess like below.
http://info.domainname.com/blog/?Tag=somedynamictag
to
http://domainname.com/tag/somedynamictag
Thanks!
First of all I don't understand the purpose of rewriting http://info.domainname.com/blog/?Tag=somedynamictag to http://domainname.com/tag/somedynamictag when it had to be the other way round. People rewrite URLs to clean them (ie. remove characters like ?,&,=, etc.) but you are adding all these and making the URLs cumbersome.
I think you didn't properly understand the concept of URL rewriting. Let me explain a little.
When any URL is accessed on your website, the URL that the USER types or clicks (in your case http://domainname.com/tag/somedynamictag) is rewritten. But your question tells me that you think the other way. Your understanding is that the visitor clicks http://info.domainname.com/blog/?Tag=somedynamictag and will be rewritten to http://domainname.com/tag/somedynamictag. THIS IS WRONG!!. If you set up your website this way, each and every URL at http://domain.com/ must exist as a separate file or directory which a dynamic website like you seem to be developing is not expected to have. So I assume you have understood that you have either misformed the question or you have you have misunderstood the concept of URL rewriting. Following is the .htaccess code to redirect http://domainname.com/tag/somedynamictag to http://info.domainname.com/blog/?Tag=somedynamictag.
RewriteEngine On
RewriteCond %{HTTP_HOST} domainname.com
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([A-Za-z0-9]+)\/(.*)$ http://info.domainname.com/blog/?$1=$2 [L,R=301]
If you think you have correctly typed the question and understood url-rewriting right and are sure what you are trying to do is right, then here's the htaccess code (if you want to redirect http://info.domainname.com/blog/?Tag=somedynamictag to http://domainname.com/tag/somedynamictag).
RewriteEngine On
RewriteCond %{HTTP_HOST} info.domainname.com
RewriteRule ^blog\/\?([A-Za-z0-9]+)=(.*)$ http://domainname.com/$1/$2 [L,R=301]
If that doesn't work, in index.php at http://info.domainname.com/blog/, place the following code:
<?php
header("HTTP/1.1 301 moved permanently");
header("Location:http://domainname.com/blog/tag/".$_GET['Tag']);
?>
And thank you for asking this question. While answering it, I learned many things.
Hope that answers your question,
Peace...

Resources