Please help to rewrite a URL - .htaccess

Sorry Please i am a new bie in url rewriting.
I have a url like this
http://www.sitename.com/subpages/detail.php?id=21-0043-052&car_name=abc
i want to redirect this site to
http://www.qualitextrading.com/vehicle-detail.php?id=21-0043-052&car_name=abc
Please how i can write this in .htaccess file
Thanks in advance

Assuming you have mod_rewrite enabled:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.sitename.com$ [NC]
RewriteRule ^\/subpages\/detail\.php(*.?)$ http://www.qualitextrading.com/vehicle-detail.php$1 [R=301,L]
This turns on rewriting for this area, then checks if the HTTP_HOST is correct, then rewrites the URL and passes on the query string (default behavior of mod_rewrite passes on query string automatically).

Related

.htaccess help! redirecting URL with query string to root

I'm new to htaccess so please bear with me..
I'm trying to redirect traffic to URLs with query string to the root of my site as these URLs are no longer used.
Here is an example:
I would like traffic to this URL
https://www.DomainName.com/subdir1/subdir2/cond_e.asp?obark=110246
to go to http://www.DomainName.com
I do not need to keep the URL or anything just redirect to my homepage.
I need to do this for query string value from obark=110246 all the way up to obark=120000.
I've basically played around with the below to get at least one URL to redirect properly but never could get it to work at all.
RewriteCond %{QUERY_STRING} ^oPark=110246$
RewriteRule ^subdir1/subdir2/cond_e(.*) ^$? [NE, R=301, L]
What am I doing wrong? please help!
Try with below rule in subdir2,
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/cond_e.asp
RewriteCond %{QUERY_STRING} ^obark=[1]{1}[1-2]{1}[0]{1}[02-9]{1}[094-5]{1}[06-9]{1}
RewriteRule ^ http://www.DomainName.com? [R=301,L]

redirect with .htaccess old url to the new url

Hell guys, can someone help me with a .htaccess rule to redirect such url type:
old url: video/displayresults/?pattern=searchedword
new url: video/search/?searchword=searchedword
So i want to redirect any old url to the new url
Thanks
You want to look up htaccess RewriteRule directive. You'll need to construct the regular expression that that it captures "/displayresults/?" and parses it into "/search/". Ensure that you have mod_rewrite enabled
Example:
RewriteRule ^(.)/displayresults/(.)$ $1/search/$2
This assumes displayresults is a folder name.
Enable mod_rewrite and .htaccess through httpd.conf (if not already enabled) and then put this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^pattern=(.*)$ [NC]
RewriteRule ^(video)/displayresults/?$ /$1/search/?searchword=%1 [L,NC,R=301]

.htaccess redirect based on url value

I have a url as below.
http://example.com/listing?listingid=237508&2000
What I want is to redirect it to a mobile version of the site.
http://example.com/mobile-listing?listingid=237508&2000
The problem is that if it is example.com/listing it should redirect to example.com/mobile-listing. If it is example.com/event it should redirect to example.com/mobile-event and so on. How am I to do this? I have seen question about redirection to mobile version based on url parameters or getvalue. But not this way. Any help would be greatly appreciated. Thanks.
i've found a simuluar answer from ulrich palha which might helps.
question id 9113747
in the .htaccess file of root you can try this:
RewriteEngine on
RewriteBase /
RewriteCond %{QUERY_STRING} (^|&)listingid= [NC]
RewriteRule ^ mobile-listing [L,R=301]
hopes this helps. you might change a little and this should point in the right direction to the solution.
You need to use a RewriteRule directive and QSA and PT flags
<VirtualHost *:80>
RewriteEngine on
RewriteRule ^/listing$ /mobile-listing [PT,QSA]
…
</VirtualHost>
Flags
PT:
Forces the resulting URI to be passed back to the URL mapping engine
for processing of other URI-to-filename translators, such as Alias or
Redirect. details ...
QSA:
Appends any query string from the original request URL to any query
string created in the rewrite target.details
More information
You can find more scenarios at Redirecting and Remapping with mod_rewrite.
Without any sort of condition for what is mobile or what isn't, and you always redirect, then the rule would look something like this:
RewriteCond %{REQUEST_URI} !^/mobile-
RewriteRule ^([^/]+)$ /mobile-$1 [L,R]
The query string will automatically get appended. Change the R to R=301 if you want to permanently redirect.

htacess url rewrites for .php?=n

I'm looking to rewrite old PHP pages to new locations, however the previous system used URLs structured as follows:
/old-page.php?page=Our%20Services
I've tried the following:
Redirect 301 /old-page.php?page=Our%20Services http://www.newdomain.co.uk/our-services/
Can someone help explain to me why the rewrite rule ignores everything after the question mark please?
You can use Redirect for simple cases only. If you want to check the query string, you must use mod_rewrite and RewriteCond
RewriteEngine on
RewriteCond %{QUERY_STRING} page=Our%20Services
RewriteRule ^old-page.php$ http://www.newdomain.co.uk/our-services/ [R,L]
This checks, if the query string contains page=Our%20Services and the URL path is old-page.php. It then redirects the client to the new URL http://www.newdomain.co.uk/our-services/.

How to rewrite my url parameter with htaccess?

I have the following url:
http://example.com/folder/index.php?module=centrale&DIO0=1
I need this page to be availeble with the following URL format:
http://example.com/folder/centrale/?DIO0=1
But how do i rewrite this using htaccess properly? What i've got so far:
RewriteEngine On
RewriteRule ^centrale/(.*)$ /index.php?module=centrale ????? $1
Notice that the DIO0 parameter is not always the only one, so the query string must be completly passed trough. Thanks in advance for helping me out or setting me in the right direction.
Edit: the htaccess file is located here: http://example.com/folder/
Try this :
RewriteEngine on
RewriteBase /folder/
RewriteRule ^centrale/$ index.php?module=centrale [L,QSA]
the [QSA] flag (Query String Append) will add the rest of the parameters automatically

Resources