I'm trying to change the name of domain using htaccess , this is i want :
http://olddomaine.com/subname/* to http://newdomaine.com/*
I'm using this solution , but the page just load without nothing :( :
Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteCond %{HTTP_HOST} !^olddomaine\.com$
RedirectMatch 301 ^/subname/$ http://newdomaine.com/
#RewriteRule (.*) http://newdomaine.com/$1 [R=301,NC]
#RewriteRule ^subname/(.*) http://newdomaine.com/$1 [R=301,NC]
You are mixing mod-rewrite with mod-alias. Both would work for your required redirects, but you should only use a single method.
The following is using mod-alias:
Options +FollowSymlinks -MultiViews
RedirectPermanent /subname http://newdomain.com/
and the following one is using mod-rewrite:
Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteRule ^subname(?:/(.*))$ http://newdomain.com/$1 [R=301,L]
Related
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]
This is my .htaccess code to rewrite clean url.
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+download\.php\?id=([^\s&]+) [NC]
RewriteRule ^ download/%1? [R=301,L]
RewriteRule ^download/([^/]+)/?$ download.php?id=$1 [L,QSA]
This code works fine for single parameter in url. For example it rewrites www.mysitename.com/download.php?id=123 to www.mysitename.com/download/123
But when I tried to pass multiple parameters in url, all I got are errors. Searched various resources and related questions but didn't got proper solution.
I need a url like www.mysitename.com/download/123/file-name instead of www.mysitename.com/download.php?id=123&name=file-name
I guess I've to use something thing like this RewriteRule ^(.*)/(.*)$ download.php?id=$1&name=$2. But while implementing I'm getting 404 error. How can I alter My code to pass multiple urls. Thanks in advance.
You just need to add a parameter in your rule
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+download\.php\?id=([0-9]+)&name=([^\s&]+)\s [NC]
RewriteRule ^ download/%1/%2? [R=301,L]
RewriteRule ^download/([0-9]+)/([^/]+)/?$ download.php?id=$1&name=$2 [L]
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]
I'm using the following configuration in .htaccess to try to rewrite URLs of the form http://www.mysite.com/subdir/page.php?param=4 to http://www.mysite.com/subdir/page/param/4:
# Turn on the rewrite engine
Options +FollowSymlinks
RewriteEngine on
# Request routing
RewriteRule ^([a-zA-Z_-]*)$ index.php?name=$1 [nc,qsa]
However, I get an Internal Server Error when I visit the page. Is there something wrong with the configuration?
EDIT: I've updated it to the following, but now it does not seem to be doing any rewriting and gives me a 404 when I try to use a URL like http://www.mysite.com/subdir/param/2:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} ^name=([0-9]+)$ [NC]
RewriteRule ^project-testing/ws/index.php$ /project-testing/ws/name/%1 [R=301,NC,L]
You need to use %{QUERY_STRING} to read the query string of your URL to redirect based on it.
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} ^param=([0-9]+)$ [NC]
RewriteRule ^subdir/page.php$ subdir/page/param/%1 [R=301,NC,L]
Or if you want that accessing:
http://www.mysite.com/subdir/page/param/4
Shows the content of:
http://www.mysite.com/subdir/page.php?param=4
Then it would be like this:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteRule ^subdir/page/([^/]+)/([^/]+)$ subdir/page.php?$1=$2 [NC,L]
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/