htaccess redirect based on url - .htaccess

How to write the htaccess rule based on
http://mysite.com/http://google.com -> http://google.com
http://mysite.com/http://facebook.com -> http://facebook.com
should redirect with 302 to that url ( except the main file index.php ), so the actual referrer would be hidden,
Thank you.

Put this code in your .htaccess under DOCUMENT_ROOT:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(https?://[^\s]+) [NC]
RewriteRule ^ %1 [R,L]

If I make the assumption that all your links will start with a protocol then the following will work:-
RewriteEngine On
RewriteBase /
RewriteRule ^(https?)://(.*)$ $1://$2 [NC,L,R=302]

Related

How could I rewrite urls properly?

I have URLs like http://url.com/top_admin/order.php?do=view&oid=124 and
I need to rewrite it to http://url.com/top_admin/order/view/124 , where
top_admin is a folder that contains my script.
this is my code:
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^order/(.*)/([0-9]+) order.php?do=$1&oid=$2 [L]
but it does not work.
With your shown samples/attempts, please try following. Please make sure to clear your browser cache before testing your URLs.
Options +FollowSymLinks -MultiViews
RewriteEngine ON
RewriteCond %{THE_REQUEST} \s/(top_admin/order)\.php\?do=([^&]*)&oid=(\d+)\s [NC]
##Rule for external rewrite with 301.
RewriteRule ^ /%1/%2/%3? [R=301,L]
##Rule for internal rewrite to .php file.
RewriteRule ^([^/]*)/([^/]*)/(.*)/?$ $1.php?do=$2&oid=$3 [L]

Domain name within domain name. How to redirect through htaccess

The crawling properties of site showing
http://www.abc.com/http://www.abc.com/index.php?option=com_toys
http://www.abc.com/http://www.abc.com/index.php?option=com_article
http://www.abc.com/http://www.abc.com/index.php?option=com_play&view=category&vid=10
The site been crawled like this, with errors coming in as duplicate url. Correct url is
http://www.abc.com/index.php?option=com_toys
http://www.abc.com/index.php?option=com_article
http://www.abc.com/index.php?option=com_play&view=category&vid=10
is there any way to 301 redirect
i tried using
RewriteCond %{REQUEST_URI} ^.*/http://www.abc.com.*$
RewriteRule .* index.php [R=301,L]
But its not achieving the desired as redirecting to http://www.abc.com/index.php
How to redirect through htaccess from incorrect url to correct url sttructure off site
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+http://.+?(/index\.php\?[^\s]+) [NC]
RewriteRule ^ %1 [R=301,L,NE]
Try this code :
RewriteEngine On
RewriteRule ^http://www.abc.com/index.php /index.php [QSA, R=301]

Redirect url to home page with trailing dots

Google webmaster showing some duplicate url,
They are
www.abc.com/index.php?option=com_toys&view=detail&n_id=148&ite..
www.abc.com/index.php?option=com_toys&view=detail&n_id=156&item..
www.abc.com/index.php?option=com_games&view=detail&vid=170&itemid..
www.abc.com/index.php?option=com_play&view=detail&vid=175&it..
To remove them - i feel the best way is to redirect to home page for any url containing .. at end of url
tried putting this condition, but it does not work too
RewriteRule ^(.*)\.htm$ http://www.abc.com/$1 [R=301,L]
RewriteRule ^(.*)$ http://www.abc.com/$1 [L,R=301]
RewriteRule ^(..*)\.htm$ http://www.abc.com/$1 [R=301,L]
Correct url structure are
www.abc.com/index.php?option=com_toys&view=detail&n_id=148&Itemid=2
www.abc.com/index.php?option=com_toys&view=detail&n_id=156&Itemid=2
www.abc.com/index.php?option=com_games&view=detail&vid=170&Itemid=3
www.abc.com/index.php?option=com_play&view=detail&vid=175&Itemid=4
any suggestions pls ... many thnx
Edit on 13th Sep
Hello Anubhav,
If we have redirect these URL to 404 page then is below command in htaccess correct
RewriteCond %{THE_REQUEST} \?.+?\.\.
RewriteRule ^index\.php$ - [NC,L,R=404]
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} \?.+?\.\.
RewriteRule ^ /? [R=301,L,NE]

Pull querystring from cgi-bin with mod_rewrite and redirect

I have a file path that looks like this: /cgi-bin/folder/script.cgi?t=1&u=http://domain.com/url/url-2/
What I want to do is create a rewrite rule to pull the querystring u= and then redirect to that URL, I've been working for a while on this with no success.
RewriteRule ^cgi-bin/folder/script.cgi?t=1&u=(.*)$ $1 [R=301,L]
Above is an example of one of my "solutions" that obviously didn't work. Any help is much appreciated. Thanks!
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+cgi-bin/folder/script\.cgi\?t=1&u=([^\s&]+) [NC]
RewriteRule ^ /%1 [R=302,L,NE]

How to Redirect URL using .htaccess?

I'm trying to redirect URLs by using the .htaccess file:
index.php?i=Dengue-NS1-ELISA-kit---Antigen&id=682&cat=0
to
index.php?i=Dengue-NS1-ELISA-kit---Antigen&id=682&cat=17
Notice the 17 on the end there.
Here is the code that you need to put in .htaccess file under DOCUMENT_ROOT:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} ^(.*)(?:^|&)cat=0(&.*|)$ [NC]
RewriteRule ^index\.php$ index.php?%1%2&cat=17 [L,NC,R]
Here maybe you can use this tool I use it all the time http://www.htaccessredirect.net/

Resources