url rewrite rule for paramters - regex

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]

Related

.htaccess RewriteRule keeping URL structure

My current rewrite rule:
RewriteEngine on
RewriteRule ^([^/\.]+)/([^/\.]+)/([^/\.]+)?$ index.php?a=$1&v=$2&id=$3 [L]
The result above works great so I can format the URL like
domain.com/a/b/c
I would like to add in a domain switch as well so the results I want is
sub.domain.com/a/b/c when you access it using domain.com/a/b/c
Currently here is what I have tried
RewriteEngine on
RewriteRule ^([^/\.]+)/([^/\.]+)/([^/\.]+)?$ index.php?a=$1&v=$2&id=$3 [L]
RewriteCond %{HTTP_HOST} ^domain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.domain.com$
RewriteRule (.*)$ http://sub.domain.com/ [R=301,L]
But the result of this is
http://sub.domain.com/a=a&v=b&id=c
and needs to be
http://sub.domain.com/a/b/c
Thanks for the help!!
Reverse the order of your rules:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]
RewriteRule (.*)$ http://sub.domain.com/$1 [R=301,L]
RewriteRule ^([^/.]+)/([^/.]+)/([^/.]+)?$ index.php?a=$1&v=$2&id=$3 [L,QSA]
Make sure to test this after clearing your browser cache.

Redirect 301 with params

I am redirecting traffic between old web and new web and I need to redirect 301 from /hotel.php?hotel=lasvegas&lng=es to http://www.new-web.com/hotel-las-vegas/
How could be possible from htaccess?
I have tried
Rewriterule ^hotel\.php\?hotel=lasvegas\&lng=es http://www.new-web.com/hotel-las-vegas/ [L,R=301]
I think my error is at regular expression. Can anyone help me?
You can use this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteBase /
# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} /hotel\.php\?hotel=lasvegas&lng=es [NC]
RewriteRule ^ hotel-las-begas? [R=302,L,NE]
# internal forward from pretty URL to actual one
RewriteRule ^hotel-las-vegas/?$ hotel.php?hotel=lasvegas&lng=es [L,QSA,NC]
it's very important that you insert best code of redirect 301 in best place of htaccess. for example :
http://www.abartazeha.com/
we replace abartazeha.com instead of abartazeha.ir
...
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^olddomain.com [NC]
RewriteRule ^(.*)$ http://newdomain.com/$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^www.olddomain.com [NC]
RewriteRule ^(.*)$ http://newdomain.com/$1 [L,R=301]

url-rewriting htacces - how to rewrite my link?

I have been looking all over the internet for this and found many clear documents on how to rewrite a url via htacces. I've gotten so far that htacces is working now, but my specific url(s) won't change. All kind of examples I have tried do not work. Hope someone here can help me with this.
This is my urL :
http://www.stamps-as-a-gift.com/category.php?cat1=Holland&cat2=Water&cat3=Vissen&cat4=Dolfijnen
No I would like it to been seen as:
http://www.stamps-as-a-gift.com/category/Holland/Water/Vissen/Dolfijnen
I like this because it is easier to remember en I have read it's also more SE friendly.
I hope this option is possible for me..thanks!
My code that isnt working:
RewriteEngine on
RewriteRule ^(cat1|cat2|cat3|cat4)/([^/.]+)/([^/.]+)/([^/.]+)$ category.php?cat=$1&cat2=$2&cat3=$3&cat4=$4
Also - do I need to restart apache after every new try ?
You need to use this rule in your root .htaccess:
Options -MultiViews
RewriteEngine on
RewriteBase /
RewriteCond %{THE_REQUEST} \s/+category\.php\?cat1=([^\s&]+)&cat2=([^\s&]+)&cat3=([^\s&]+)&cat4=([^\s&]+)\s [NC]
RewriteRule ^ category/%1/%2/%3/%4? [R=302,L]
RewriteCond %{THE_REQUEST} \s/+category\.php\?cat1=([^\s&]+)&cat2=([^\s&]+)&cat3=([^\s&]+)\s [NC]
RewriteRule ^ category/%1/%2/%3? [R=302,L]
RewriteCond %{THE_REQUEST} \s/+category\.php\?cat1=([^\s&]+)&cat2=([^\s&]+)\s [NC]
RewriteRule ^ category/%1/%2? [R=302,L]
RewriteCond %{THE_REQUEST} \s/+category\.php\?cat1=([^\s&]+)\s [NC]
RewriteRule ^ category/%1/? [R=302,L]
RewriteRule ^category/([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$ category.php?cat1=$1&cat2=$2&cat3=$3&cat4=$4 [L,QSA,NC]
RewriteRule ^category/([^/]+)/([^/]+)/([^/]+)/?$ category.php?cat1=$1&cat2=$2&cat3=$3 [L,QSA,NC]
RewriteRule ^category/([^/]+)/([^/]+)/?$ category.php?cat1=$1&cat2=$2 [L,QSA,NC]
RewriteRule ^category/([^/]+)/?$ category.php?cat1=$1 [L,QSA,NC]

Apache Rewrite Issue. Unable to figure out query string

So I have been struggling on finding the rule to match this rewrite. I am working on a client website and it is a nightmare with the number of duplicate title tags. I have managed to resolve most of them by enforcing forward slash, redirect non www. to the www. version and disallow crawling of https version of the website.
The issue I am having at the moment. I have over 1000 URLs that are duplicate content, each product has two different URLs with the exact same content. An example is:
http://www.example.co.uk/product/widget1/
http://www.example.co.uk/widget1/
http://www.example.co.uk/product/widget2/
http://www.example.co.uk/widget2/
Now the following URLs have the same content:
http://www.example.co.uk/product/widget1/
http://www.example.co.uk/widget1/
I want to redirect any URL that contains "/product/" to the URL version without "/product/" in the URL if that makes sense. I honestly don't know where to start and would really appreciate the help.
Thanks in advance
EDIT: The recommended rule:
RewriteEngine On
RewriteRule ^/product/(.*)$ /$1 [R=301]
does not work. It may be conflicting. These are the other rules:
RewriteEngine On
RewriteCond %{QUERY_STRING} .+
RewriteRule ^(.*)$ /$1? [R=301,L]
RewriteRule ^/product/(.*)$ /$1 [R=301]
RewriteCond %{HTTP_HOST} ^example\.co [NC]
RewriteRule (.*) http://www.example.co.uk/$1 [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)([^/])$ /$1$2/ [L,R=301]
I dont know if there are any conflicts here. Please help
Have your full .htaccess like this:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.co [NC]
RewriteRule (.*) http://www.example.co.uk/$1? [L,R=301]
RewriteCond %{QUERY_STRING} .+
RewriteRule ^(.*)$ /$1? [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+?[^/])$ /$1/ [L,R=301]
RewriteRule ^product/([^/]+)/?$ /$1/ [R=301,L]
Assuming the URLs always start with product, this should work:
RewriteEngine On
RewriteRule ^/product/(.*)$ /$1 [R=301]
It'll need to go in your main site conf or .htaccess

detect and redirect based on URL

I have the following conditions in my .htaccess file:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^ex\.co$
RewriteRule ^(.*)$ http://example.com/?ref=$1 [L,R]
This will forward ex.co\xxxxxx to example.com\?ref=xxxxxx.
What I want is to add a line that if a user simply goes to ex.co it redirects to example.com and not (as it does currently) example.com?ref=
Any suggestions?
Thanks!
I think you just need to add the third line below:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^ex\.co$
RewriteRule ^$ http://example.com [L,R]
RewriteRule ^(.*)$ http://example.com/?ref=$1 [L,R]