I want to rewrite an URL like this
http://domain1.com/some_directory/12345678?x=1/audio.mp3
to an URL like this http://domain2.com/12345678?x=1.
I tried this rewrite rule RewriteRule /some_directory/(.*)$/(.*).mp3 http://domain2.com/$1 [NC,L] but it doesn't work.
You can use this rule in root .htaccess by matching query string in a RewriteCond:
RewriteEngine On
RewriteCond %{QUERY_STRING} (?:^|&)(x=\d+)[^.]+\.mp3 [NC]
RewriteRule ^some_directory/(.*)$ http://domain2.com/$1?%1 [NC,L,R=302,NE]
Related
How to rewrite a URL from localhost/folder/abc.php?p_id=1 to localhost/folder/xyx/1.
I tried lots of methods but still couldn't rewrite the URL.
RewriteEngine On
RewriteRule ^xyx/(.+)$ folder/abc.php?p_id=$1 [L]
You can use this rule inside folder/.htaccess:
RewriteEngine On
RewriteRule ^xyz/(.+\.(?:css|js))$ /folder/$1 [L,R=301,NE,NC]
RewriteRule ^xyz/(.+) abc.php?p_id=$1 [L,QSA,NC]
I have the following URL:
https://www.mydomain.de/termin_cancel=c502b486-e8ad-490a-a615-80307a515fc8
Original url:
https://www.mydomain.de/index.php?termin_cancel=c502b486-e8ad-490a-a615-80307a515fc8
rewrite rule:
RewriteRule ^termin_cancel=([\w-]+)/?$ index.php?termin_cancel=$1 [L,NC,QSA]
This works !
But now I have a problem with the next situation:
The url should be:
https://www.mydomain.de/termin_change=XXX&serviceID=XXX&firstname=XXX&lastname=XXX&email=XXX
original url:
https://www.mydomain.de/index.php?termin_change=XXX&serviceID=XXX&firstname=XXX&lastname=XXX&email=XXX
I don't know which htaccess rule work fo this.
It should be possible to access the parameters via php $_GET.
This should work for you.
RewriteRule ^termin_change=([^&]+)&serviceID=([^&]+)&firstname=([^&]+)&lastname=([^&]+)&email=([^&]+)$ /index.php?termin_change=$1&serviceID=$2&firstname=$3&lastname=$4&email=$5 [L,NC]
Could you please try following.
RewriteEngine ON
RewriteRule ^(.*) index.php?$1 [QSA,NE,L]
OR with / in case your index.php is present in root directory/folder.
RewriteEngine ON
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^(.*) /index.php?$1 [QSA,NE,L]
OR(either put above or put following)
RewriteEngine ON
RewriteCond %{QUERY_STRING} ^$
RewriteCond %{REQUEST_URI} ^/termin_change=.*/?$ [NC]
RewriteRule ^(.*) /index.php?$1 [QSA,NE,L]
Try, something like below specifically for termin_change=
RewriteRule ^termin_change=(.+)/?$ index.php?termin_change=$1 [L,NC,QSA]
I need to use this url http://yoursite.com/proprietes.php?viewid&mls=[18348939] but I wan it to go on a pdf a-very-new-post.pdf. I want to do a redirection in the htaccess. It is not working... I'm in wordpress
thanks!
RewriteEngine On
Redirect 301 /proprietes.php?viewid&mls=[18348939]$ http://yoursite.com/a-very-new-post.pdf
Redirect or RewriteRule directives cannot match query string. Use a RewriteCond instead like this:
RewriteEngine On
RewriteCond %{THE_REQUEST} \s/proprietes\.php\?viewid&mls=\[?18348939\]? [NC]
RewriteRule ^ /a-very-new-post.pdf? [L,B,R=301]
RewriteCond %{THE_REQUEST} \s/en/proprietes\.php\?viewid&mls=\[?18348939\]? [NC]
RewriteRule ^ /a-very-new-post-english.pdf? [L,B,R=301]
I'm trying to rewrite my website URLs. I have:
http:// website.com/v2/message.php?ID2=123
I want:
http:// website.com/v2/message-123.php
I tried something in my htaccess but I've a redirection loop :'(
Here is my .htaccess:
RewriteCond %{QUERY_STRING} ^ID2=([0-9]+)$
RewriteRule message.php? http://website.com/v2/message-%1.php? [L,R=301]
Can someone help me with this?
I suggest not using .php in pretty URL, make it extension-less. Try these rules in v2/.htaccess:
RewriteEngine On
RewriteBase /v2/
RewriteCond %{THE_REQUEST} /message\.php\?ID2=([^&\s]+) [NC]
RewriteRule ^ message-%1? [NE,R=302,L]
RewriteRule ^message-(.+)/?$ message.php?ID2=$1 [L,QSA,NC]
I have the following example urls that i need redirecting to www.example.co.uk
http://www.example.co.uk/wordpress/?feed=comments-rss2
http://www.example.co.uk/wordpress/?feed=rss2
http://www.example.co.uk/wordpress/?cat=518
http://www.example.co.uk/wordpress/?cat=514
http://www.example.co.uk/wordpress/?cat=520
http://www.example.co.uk/wordpress/?cat=521
http://www.example.co.uk/wordpress/?cat=523
http://www.example.co.uk/wordpress/?cat=515
http://www.example.co.uk/wordpress/?p=119
There are many more urls further to this list that all have a wordpress/ notation.
Would I have to write a conditional rewrite for each like this:
RewriteCond %{QUERY_STRING} ^feed=comments-rss2$
RewriteRule ^/wordpress/?(.*)$ http://www.example.co.uk [R=301,L]
RewriteCond %{QUERY_STRING} ^cat=518$
RewriteRule ^/wordpress/?(.*)$ http://www.example.co.uk [R=301,L]
or is there a rule i can write that redirect all urls that have /wordpress in them to redirect to www.example.co.uk
I believe a single rule like would be suffice:
RewriteCond %{QUERY_STRING} (^|&)(feed|p|cat)=[^&]+ [NC]
RewriteRule ^wordpress(/.*)?$ http://www.example.co.uk/? [R=301,L,NC]
Make sure this is very first rule in your .htaccess just below RewriteEngine On line.