.htaccess redirect for dynamic search pages - .htaccess

I need help with dynamic search pages. I need to change:
/download.php?q=search
to
/download.php?mp3=search
So only search pages need to change q to mp3.
I would appreciate if someone could help. I want to do this through .htaccess
Thanks in advance

The query string is only available as a variable with RewriteCond. Something like this should work:
RewriteCond %{QUERY_STRING} q=([^&]*)
RewriteRule ^download.php download.php?mp3=%1 [L,QSA,NC]

something like that:
RewriteRule ^/download.php?q=(.*) /download.php?mp3=$1 [L]

Related

Transform(redirect) URL segment to a GET parameter

I know this has probably been answered but I can't find anything specific to my issue.
I have URLS like this:
https://staging.books.co.za/travelguide/route-map/SAFI546754
https://staging.books.co.za/travelguide/route-map/SAFI189444
https://staging.books.co.za/travelguide/route-map/SAFI978634
and I need them to be redirected to URLS like this:
https://staging.books.co.za/travelguide/route-map?reference=SAFI546754
https://staging.books.co.za/travelguide/route-map?reference=SAFI189444
https://staging.books.co.za/travelguide/route-map?reference=SAFI978634
Please help...What would the rule look like in my .htaccess file???
This should do the trick:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^travelguide/route-map/(.+) /travelguide/route-map?reference=$1
See here for a demo http://htaccess.mwl.be?share=6c2be57a-6bb7-5083-9122-aaf63162b240
Try and use this in your .htaccess:
RewriteEngine On
RewriteRule ^travelguide/route-map/([-a-zA-Z0-9_]+)/?$ route-map?reference=$1 [L]
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

Rewrite using .htaccess if query string is empty

Might be a quick question for someone but it's not an area I have a huge amount of knowledge in.
I want to rewrite a URL using .htaccess if the query string is empty:
http://mydomain.com/js/file.js?foo=
So it rewrites to something like:
http://mydomain.com/js/error.js
Thanks in advance.
RewriteCond %{QUERY_STRING} ^foo=$
RewriteRule ^js/file.js$ /js/error.js [R=301,L]

URL Rewriting.htaccess

I want to rewrite a URL through htaccess, but I am not getting the solution to do the specific rewriting. For e.g., I have a URL:
http://www.yourdomain.com/page/about-us.html
Now I want to remove page from above URL, so it should look like;
http://www.yourdomain.com/about-us.html
Can anybody help me with this.
Thanks in advance.
Something like this should work:
RewriteEngine on
RewriteRule ^about-us.html$ /page/about-us.html
If you need it done on any URL put into the site, then something like this:
RewriteEngine on
RewriteRule ^([_\&\'\,\+A-Za-z0-9-]+).html$ /page/$1.html
Assuming you want a 301:
RewriteEngine on
RewriteRule ^page/about-us.html$ /about.html [R=301,L]

.htaccess mod-rewrite question

hey there, i have quite some issues with the mode rewrite here is what i use :
RewriteEngine On
RewriteRule ^([^/]*)/([^/]*)$ /creatii.php?creatie_thumb=$2&user=$1 [L]
RewriteRule ^([^/]*)/$ /creatiiuser.php?user=$1
i would like this link :
http://creatii.artcrew.ro/creatii.php?creatie_thumb=creatie19&user=dee-dee
to look:
like http://creatii.artcrew.ro/dee-dee/creatie19
well this is fine, it works, no problems with it but i want to make a rule for another link
http://creatii.artcrew.ro/categorii.php?numecat=poetry&numesubcat=satire
to look like
http://creatii.artcrew.ro/poetry/satire
how can i do this? what rules must i use?
currently if i access http://creatii.artcrew.ro/poetry/satire
it access the link : http://creatii.artcrew.ro/creatii.php?creatie_thumb=satire&user=poetry
how can i make both links(the first one and the second one) work?
one more thing, i want this link : http://creatii.artcrew.ro/creatiiuser.php?user=Dan to look like http://creatii.artcrew.ro/Dan or if that does not work http://creatii.artcrew.ro/user/Dan
how can i do that?
can anyone help me?
thanks in advance
Given the URL http://creatii.artcrew.ro/X/Y, how is mod_rewrite supposed to know whether X and Y are creatie_thumb and user values or numecat and numesubcat values?
You need to add something to the URL to differentiate these cases.
For example:
http://creatii.artcrew.ro/user/dee-dee
http://creatii.artcrew.ro/user/dee-dee/creatie19
http://creatii.artcrew.ro/cat/poetry/satire
RewriteEngine On
RewriteRule ^user/([^/]*)/([^/]*)$ /creatii.php?creatie_thumb=$2&user=$1 [L]
RewriteRule ^user/([^/]*)/$ /creatiiuser.php?user=$1 [L]
RewriteRule ^cat/([^/]*)/([^/]*)$ /creatii.php?numecat=$1&numesubcat=$2 [L]
Maybe you're too much generic with your rules and you got conflicts.
Try to map this urls
http://creatii.artcrew.ro/creatii/dee-dee/creatie1
http://creatii.artcrew.ro/categorii/poetry/satire
Starting from those sample you can easily map your urls with no conflict on rules
RewriteEngine On
RewriteRule ^creaati/([^/]*)/([^/]*)$ /creatii.php?creatie_thumb=$2&user=$1 [L]
RewriteRule ^categorii/([^/]*)/([^/]*)$ /categorii.php?numecat=$1&numesubcat=$2 [L]
Do some tries :D

Resources