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

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]

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.

.htacess url rewrite rule to shortern the url and remove "?st_id=" from it

I currently goto:
support-requests/?st_id=7
Ideally i would like to just go straight here using .htaccess url-rewriting to make the page neater to look at and navigate to without the "?st_id=" being displayed in the url.
support-requests/7
This is what i currently have but i know its wrong and it does not work:
RewriteCond %{QUERY_STRING} ^(\w+)=(\w+)$
RewriteRule support-requests/ support-requests/%1/%2/?
Could i have some assistance in getting this correct please?
Thanks
Use this:
RewriteEngine On
RewriteRule ^support-requests/([^/]*)$ /support-requests/?st_id=$1 [L]
Should leave you with:
www.example.com/support-requests/7

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

Rewrite rule doesn't work on joomla htaccess

I need a redirect from http://www.mysite.com/passport/365.html to http://www.mysite.com/passport/365.html?task=view
I try to do it like this
RewriteCond %{HTTP_HOST} ^/passport/365.html$
RewriteRule ^/?$ /passport/365.html?task=view [QSA]
and it doesn't work.
Please help.
try that :
RewriteEngine on
RewriteRule ^passport/365\.html$ http://www.mysite.com/passport/365.html?task=view [R]
I think in you example ur missing the **
so it should be something like :
RewriteRule ^/passport/365\.html$ /passport/365\.html?task=view [QSA]
I would recommend you use this plugin.
You can simply add the redirect rule to the plugin without modifying .htaccess
There is a component already build in Joomla called "redirect" where U can set-up your redirects, so you don't have to use .htaccess at all.
Here is a good tutorial: http://www.joomtraining.com.au/tutorials/joomla-1.6/creating-a-page-redirect
The problem with the .htaccess is that every redirect must be set in appropriate place in the file.

Regular Expression For URL Query

I've been using mod_rewrite in my htaccess file to rewrite my urls and I've run into a problem when doing pagination.
Here's the url for my page:
http://domain.com/concerts/features/folk-roots?page=2
htaccess file:
RewriteRule ^features/([^/]*)?page=([0-9]*)$ featureCat.php?cat=$1&page=$2 [NC,L]
It works fine without the page query, but if I want to change pages I can't figure out how to write the regular expression to grab the page #.
Any ideas would be appreciated!
You need to use RewriteCond immediately before the RewriteRule to get access to the query string:
RewriteCond %{QUERY_STRING} ^page=([0-9]*)$
RewriteRule ^features/([^/]*)$ featureCat.php?cat=$1&page=%1 [NC,L]

Resources