I have url pattern like this.
site.com/page-name?variable-name=variable value
I want this to be site.com/variable - value
I' am not good in rewrite api. Please guide me through .htaccess.
Try this
RewriteEngine On
RewriteCond %{QUERY_STRING} ^(.*)=(.*)
RewriteRule ^(.*) /%1-%2? [R,L]
Related
I've never needed to use a .htaccess before and I'm fairly new to coding I'm trying to get localhost/index.php?id=123456789 to be passed as localhost/123456789/ but I just cant get the HTaccess right, i've tried everything I could find from prevoius posts here, haha!
My current HTACCESS looks like this, however it doesnt do what I want.
RewriteEngine On
RewriteRule ^id/(\d+)$ /index.php?id=$1 [NC,QSA,L]
You can do it with mod_rewrite in .htaccess however I'm not sure from your question which direction you want it to be passed to.
If you want people to type the php script in the URL bar you want:
RewriteEngine on
RewriteCond %{QUERY_STRING} id=([0-9]+)
RewriteRule ^index.php$ %1/
Or if you want people to enter the "pretty" version but for your server to load the PHP script you need:
RewriteEngine on
RewriteRule ^([0-9]+)/$ index.php?id=$1&%{QUERY_STRING}
For both ways and 301 redirect to pretty URL:
RewriteEngine on
RewriteRule ^([0-9]+)/$ index.php?id=$1&%{QUERY_STRING} [L]
RewriteCond %{QUERY_STRING} id=([0-9]+)
RewriteRule ^index.php$ %1/ [L,R=301]
I'm trying to rewrite part of a URL with a 301 htaccess rewrite.
So far I got this
RewriteRule ^index.php?option=com_payplans&view=subscription&task=display&subscription_key=(.*)$ /subscriptiondetails/display/$1 [R=301,L,NC]
I want to go from
http://www.example.com/index.php?option=com_payplans&view=subscription&task=display&subscription_key=8O56WXCMQEZ5
to
http://www.example.com/subscriptiondetails/display/8O56WXCMQEZ5
Just can't quite figure out what I'm missing or doing wrong.
You need to use a RewriteCond to match query string:
RewriteCond %{QUERY_STRING} ^option=com_payplans&view=subscription&task=display&subscription_key=(.*)$
RewriteRule ^index\.php$ /subscriptiondetails/display/%1? [R=301,L,NC]
I have lot or articles with this URL format:
mydomain/art/details.php?articleid=24463&parentid=1&catid=166
the above is an example.
And i want that redirect these kind of URL to :
mydomain/art/24463.html
Please let me know that how can i do it with .htaccess?
Thanks in advance
Instead of mydomain/art/24463.html you should choose something like mydomain/art-166/1-24463.html.
This way, you'll include also parentid and catid which are dynamic parameters (and so, needed for rewriting).
RewriteEngine On
RewriteCond %{THE_REQUEST} \s/art/details\.php\?articleid=(\d+)&parentid=(\d+)&catid=(\d+)\s [NC]
RewriteRule ^ /art-%3/%2-%1.html? [R=301,L]
RewriteRule ^art-(\d+)/(\d+)-(\d+)\.html$ /art/details.php?articleid=$3&parentid=$2&catid=$1 [L]
Try this in htaccess tester
RewriteEngine on
RewriteRule ^art/(\d+).html$ art/details.php?articleid=$1&parentid=1&catid=166 [nc]
Now, I'm trying to write some htaccess code with mod_rewrite. I have problem with it :(
RewriteEngine On
RewriteRule ^home$ index.php?page=home
This is my code in .htaccess file. When I go to domena.com/index.php?page=home it's exactly same like domena.com/home
But, It's not friendly for google, 'cos we have double page:
domena.com/index.php?page=home
domena.com/home
It's same.
What I want to achieve? I want to user who choose domena.com/index.php?page=home redirect him to domena.com/home
Exactly, I want to on my website be exist ONLY friendly link.
Help me :(
You will need another rule to redirect old URL to new one.
You can use this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} /index\.php\?page=([^\s&]+) [NC]
RewriteRule ^ %1? [R=302,L,NE]
RewriteRule ^home/?$ index.php?page=home [L,NC,QSA]
How to rewrite
/?custom_ref=
with
/?ref=
using htaccess rewrite???
RewriteEngine On
RewriteCond %{QUERY_STRING} custom_ref=(.*)
RewriteRule (.*) /?ref=%1 [R=301,L]
Can you please tell me the directory/file that you using this query on so I make sure this code will only work with it.