htaccess rewrite url parameter - php

I want to redirect
http://localhost:8080/mypproject/?supplier=test123
to
http://localhost:8080/myproject/?product_cat=test123
But I don't know how...

You can use this code in your /myproject/.htaccess file:
RewriteEngine On
RewriteBase /myproject/
RewriteCond %{QUERY_STRING} ^supplier=([^&]+) [NC]
RewriteRule ^/?$ ?product_cat=%1 [L,R=301]

Related

How to pass multiple parameter in .htaccess

I have url that I want to rewrite so it can pass the parameter like this
From www.example.com/questions.php/postid=101&title=htaccess_tuts
To www.example.com/questions.php/postid/1/title/htaccess_tuts
I have been trying to get this done using below .htaccess but i end up getting this
From www.example.com/questions.php/postid=1&title=htaccess_tuts
To www.example.com/questions.php/postid/101
The title part didn't show.
Can anyone help me pass it multiple parameter
RewriteBase /
#Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
#here is the problem i have don this but didn't work
#RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+questions\.php\?postid=([^\s&]+)&([^\s&]+) [NC]
#What can i do again?
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+questions\.php\?postid=([^\s&]+) [NC]
RewriteRule ^ questions/%1? [R=301,L]
RewriteRule ^questions/([^/]+)/?$ questions.php?postid=$1&title=$2 [L,QSA]
RewriteEngine On
RewriteRule ^questions\.php/postid/([^/]*)/title/([^/]*)$ /questions.php?postid=$1&title=$2 [L]
you can use this site for generate rewrite rules

Rewrite url not working in htaccess

I have website. I just want to rewrite url using .htaccess
Here is the code which I want to rewrite:
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} /search_data.php\?keywords=([^&]+)&f=([^\s&]+) [NC]
RewriteRule ^/search_data.php/?$ /search/%1/%2? [R=301,L,NC]
this the current url
http://localhost/mywbsite/search_data.php?keywords=one+piece&f=149
I want to convert this to this
http://localhost/mywbsite/search/one-piece/149
I tried above code but its not working please help me
QUERY_STRING is only used to match query string without URI.
You need to use:
Options -MultiViews
RewriteEngine On
RewriteBase /mywbsite/
RewriteCond %{THE_REQUEST} /search_data\.php\?keywords=([^&]+)&f=([^\s&]+) [NC]
RewriteRule ^ search/%1/%2? [R=301,L]
RewriteRule ^search/([^/]+)/([^/]+)/?$ search_data.php?keywords=$1&f=$2 [QSA,L,NC]

How to rewrite these url on htaccess

i want to rewrite these URL
getimage.php?videoid=myquery
to
img/myquery
i try this ht access code but after this its show empty page
RewriteEngine On
RewriteBase /
RewriteRule ^img/(.+) getimage.php?videoid=$1
please tell me how to set it
You can use this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} /getimage.php\?videoid=([^\s&]+) [NC]
RewriteRule ^ img/%1? [R=302,L,NE]
RewriteRule ^img/([^/.]+)/?$ getimage.php?videoid=$1 [L,QSA,NC]
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} videoid=(.+)
#RewriteRule getimage.php$ /img/%1? [R=301,L] #redirect
RewriteRule getimage.php$ test/%1? [L] #rewrite

htaccess redirect for query url including a path

I have to redirect url
http://www.nv-pedia.de/pedia/?q=node/630
to
http://www.nv-pedia.de/hafenplan-s256-arsdale/
My solutions doesn´t do anything and unfortunately i have not found an answer on this.
RewriteEngine On
RewriteCond %{QUERY_STRING} (^|&)630(&|$) [NC]
RewriteRule $/hafenplan-s256-arsdale/? [R=301,L]
You can use:
RewriteEngine On
RewriteCond %{QUERY_STRING} (^|&)q=node/630(&|$) [NC]
RewriteRule ^pedia/?$ /hafenplan-s256-arsdale/? [R=301,L,NC]

Modify .htaccess to make URL?variable=true change to URL/variable?

I'm trying to change my .htaccess file so that if I go to:
http://www.example.com/index.php?login=true, it goes to http://www.example.com/login.
I currently have this code which removes index.php (which makes the above looks like http://www.example.com/?login=true).
RewriteEngine On
#remove index.php
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteCond %{THE_REQUEST} !/system/.*
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,L]
RewriteCond %{THE_REQUEST} ^GET
I would setup your rewrite rule the other way around:
RewriteEngine On
RewriteRule ^login$ /index.php?login=true
This way if a user browses to http://yourserver.com/login the actual page used is http://yourserver.com/index.php?login=true, but the first URL is shown in the browser. I assume this is what you are trying to achieve.
If you really need to do it in the direction you asked for, you can try something like this:
RewriteEngine on
RewriteCond %{QUERY_STRING} ^login=true$
RewriteRule ^index\.php$ /login [L,R=301]
This will fail of there are additional query parameters.
If you want to redirect http://yourserver.com/index.php to http://yourserver.com you can simply add the following rewrite rule:
RewriteRule ^index\.php$ / [L,R=301]
The following should work although there might something wrong with the line to exclude /system/*. Try testing with that commented out.
RewriteEngine On
RewriteCond %{QUERY_STRING} ([^=]*)=true [NC]
RewriteCond %{THE_REQUEST} ^/system/.*
RewriteRule index.php /%1? [R=301,L]
The following page helped: http://wiki.apache.org/httpd/RewriteQueryString
This tester is cool but does have a few bugs in it: http://martinmelin.se/rewrite-rule-tester/
try the following in the .htaccess in root directory of example.com
RewriteEngine On
RewriteBase /
#rewrite http://www.example.com/anything to http://www.example.com/index.php?anything=true
RewriteCond %{REQUEST_URI} ^/([-a-zA-Z0-9]+)$ [NC]
RewriteCond %1 !system [NC]
RewriteRule . index.php?%1=true [L]
#301 redirect requests for example.com/index.php?anything=true to example.com/anything
RewriteCond %{REQUEST_URI} ^/index\.php$ [NC]
RewriteCond %{QUERY_STRING} ^([^=]+)=true$ [NC]
RewriteRule . /%1? [L,R=301]
You need to check for the QUERY_STRING in a RewriteCond. I think this should do:
RewriteEngine On
#remove index.php
RewriteCond %{QUERY_STRING} ([^=]*)=true [NC]
RewriteCond %{THE_REQUEST} !/system/.*
RewriteRule ^index\.php /%1? [R=301,L]
This should redirect anything which has index.php?=true to /action

Categories