How to rewrite my url parameter with htaccess? - .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

Related

rewrite rule to convert php querystring to html

Please help me in writing correct .htaccess code to get the wanted result.
I have the following pages:
www.mydomain.com/?exam=/hp-certification/
www.mydomain.com/?exam=/cisco-certification/
www.mydomain.com/?exam=/oracle-exam-prep/
www.mydomain.com/?exam=/faq/
www.mydomain.com/?exam=/support/
And there are many more pages but you can notice that the fixed part is: www.mydomain.com/?exam=
Instead of using query string links, I want the following links to work as above pages:
www.mydomain.com/hp-certification/
www.mydomain.com/cisco-certification/
www.mydomain.com/oracle-exam-prep/
www.mydomain.com/faq/
www.mydomain.com/support/
and so on.
your link should be like this www.mydomain.com/?exam=hp-certification/ and the rewrite rule would like this in .htaccess file.
RewriteEngine On
RewriteRule ^([^/.]+)$ /?exam=$1 [L]
You can do that by using the following rules in your .htaccess file:
RewriteEngine On
RewriteCond %{QUERY_STRING} exam=(.+) [NC]
RewriteRule ^(.*)$ http://www.example.com/%1? [R=301,NC,L]
So what does the above do?
First, it will take the query exam= as a condition, if this condition is met then it will grab any version of the variable using (.+).
It will then rewrite the URL using 301 redirection to show http://www.example.com/anything/. The use of %1 is to grab the variable from exam= and then we use ? to stop the original query string from appearing on the end of the newly rewritten URL.
Make sure you clear your cache before testing this.

Using .htaccess to remove PHP parameters from URL(without reloading the page)

I am trying to work out how to remove the $_GET parameters from a URL.
I am using PHP to switch content so I can use one page(index.php).
An example URL is: www.example.com/?page=test OR www.example.com/index.php?page=test
I want it so if anything after and including the ? is removed.
So the result will always show: www.example.com/ OR www.example.com
Thanks in advanced.
Put this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^page=test$
RewriteRule ^(index.php)?$ $0? [L,NC]

Please help to rewrite a URL

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).

restricting input of GET url on htaccess rewrite url

My original url is : www.site.com/report.cgi?d=2012-05
Requested URL: www.site.com/report-2012-05.cgi
My Htaccess Code:*
RewriteRule ^report([^/]*)\.cgi$ /report.php?d=$1 [L]
I want to restrict the request parameter to just XXXX-XX number format in GET url.
How can I do this ?
I didn't really understand your question, except you want to modify the URL format placing the parameter value in a different position.
The best way to do it is by capturing the query string like this:
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} d=(.*)
The value inside the round brackets is the parameter value (2012-05), which can be back referenced with %1. For example:
RewriteRule .* report-%1.cgi [L]
Will rewrite the URL with /report-2012-05.cgi
Hope this helps.
I think you need to remove .cgi from your rewrite rule
For www.site.com/report-xxxx-xx
RewriteRule ^report-([^/]*)$ /report.cgi?d=$1 [L]<br>
For www.site.com/xxxx-xx
RewriteEngine On
RewriteRule ^([^/]*)$ /report.cgi?d=$1 [L]

mod_rewrite help can't get it to work

This is the first time I use mod_rewrite and I can't get it to work. I have a website with bands and their IDs. What I want:
a URL /bands/My_Band_id13/ should redirect to /bands/index.php?bandname=My_Band&bandID=13
What I have:
RewriteRule ^/bands/(.*)_id(.*)/$ /bands/index.php?bandname=$1&bandID=$2
What am I doing wrong?
try adding the 'qsappend|QSA' (query string append) rewrite flag to your rule, ie.
RewriteRule ^/bands/(.*)_id(.*)/$ /bands/index.php?bandname=$1&bandID=$2 [QSA]
UPDATE: also, try removing / outcommenting your RewriteBase /. if this doesn't work, neither, try moving your .htaccess file into the same directory your index.php is in and adapt the RewriteRule, eg.
RewriteRule ^(.*)_id(.*)/$ index.php?bandname=$1&bandID=$2 [QSA]

Resources