How to Redirect URL using .htaccess? - .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/

Related

.htaccess redirect a dynamic page to an external page URL won't work

I need to redirect a few specific dynamic php pages to an external website domain. For example,
siteA.com/home/space.php?uid=357&do=thread&id=396
to
siteB.com
I put the following in my .htaccess but it didn't work.
Options +FollowSymlinks -MultiViews
RewriteEngine On
Redirect home/space.php?uid=357&do=thread&id=396 http://www.siteB.com
what's wrong with this? any suggestion is appreciated. thanks!
From this:
Redirect home/space.php?uid=357&do=thread&id=396 http://www.siteB.com
to this:
RewriteRule ^[home/space.php?uid=357&do=thread&id=396]+$ http://www.siteB.com [R=301,L]
You need to use RewriteCond for matching query string:
Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteCond %{QUERY_STRING} ^uid=357&do=thread&id=396$ [NC]
RewriteRule ^home/space\.php$ http://www.siteB.com [L,NC,R=302]

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]

htaccess redirect based on url

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]

Rewrite rule in htaccess is not working properly

I am trying to redirect the url:
'mysiteurl/Actors/as23sderd/1' to 'mysiteurl/cataImages.php?c=Actors&p=1'
using the following htacess code:
RewriteEngine On
RewriteRule ^([\w]+)/([a-zA-Z0-9]+)/([0-9]+)$ cataImages.php?c=$2&p=$3
But it is not redirecting now.
Please help me.
RewriteEngine On
RewriteRule ^([\w]+)/([a-zA-Z0-9]+)/([0-9]+)$ cataImages.php?c=$1&p=$3
This is what you need:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^[^/]+/([^/]+)/([0-9]+)/?$ cataImages.php?c=$1&p=$2 [L,QSA,NC]

change url .htaccess php

I have a page name page.php and my url as localhost/mysite/page.php , now how can i change the url using .htaccess file to localhost/mysite/somethinghere1/somethinghere2/page.php
It tried using the below code but it doesn't work out.
<IfModule mod_rewrite.c>
# Enable Rewriting
RewriteEngine On
# Rewrite user URLs
# Input: user/NAME/
# Output: user.php?id=NAME
RewriteRule ^somethinghere1/somethinghere2/.php? page.php
</IfModule>
how can i acheive this.
What about this:
RewriteRule ^somethinghere1/somethinghere2/([^/\.]+).php/?$ page.php
Use it like this:
RewriteRule ^(mysite/)somethinghere1/somethinghere2/(.*\.php)/?$ $1$2 [L,NC]
Also make sure this in .htaccess file in your DOCUMENT_ROOT directory.
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^([^/]+)/([^/]+)/page.php /page.php?first=$1&second=$2 [NC]
This is the basic code , you can play with it to fit your needs like the following edit :
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^([^/]+)/([^/]+)/([^/]+) /$3.php?first=$1&second=$2 [NC]
So x/y/z would be z.php?first=x&second=y

Resources