htacces - subdomain with get parameters - .htaccess

i want to rewrite a subdomain with get parameters.
My subdomain like :
vouchers.domain.com
This is my called domain:
vouchers.domain.com?url=test.de
This file get zero or one parameter
vouchers.php
My first try looks like this:
RewriteCond %{HTTP_HOST} vouchers.domain.com(.*?)
RewriteCond %{REQUEST_URI} !vouchers.php
RewriteRule ^$ vouchers.php?url=%1 [QSA,L,NC]
But it doesn't work.
Could anyone help me to fix it?
Thanks

You can use:
RewriteCond %{HTTP_HOST} ^vouchers\.domain\.com$ [NC]
RewriteRule !^vouchers\.php$ vouchers.php?url=%{REQUEST_URI} [QSA,L,NC]

Related

How to redirect dynamic subdomains with multiple query parameters

I would like to redirect
domain.com/test.php?username=username&code1=849&code2=4d1
to
username.domain.com/849/4d1
with .htaccess
At the moment I have
RewriteRule ^test/([^/]+)/([^/]+)/([^/]+) test.php?username=$1&code1=$2&code2=$3 [NC]
RewriteCond %{HTTP_HOST} ^(^.*)\.domain.com
RewriteRule ^(.*) test.php?username=%1&code1=%2&code2=%3 [NC]
The redirect works but the code (php)
$code1 = $_GET['code1'];
echo $code1;
is empty. Can anyone point me in the right direction?
Thanks
Found it!
So if you want to redirect
username.domain.com/849/4d1
to
domain.com/test.php?username=username&code1=849&code2=4d1
You need to add below code to your .htaccess file:
RewriteCond %{HTTP_HOST} ^(^.*)\.domain.com
RewriteRule ^(.*)/([^/]+) test.php?username=%1&code1=$1&code2=$2 [NC]

How do I ignore the end of a url parameter string in Htaccess?

I have a bunch of ugly links coming in to a site like this:
https://www.somedomain.com/mm5/mch.mvc?Session_ID=5f59c6e0&Screen=PRODFB&Product_Code=pcode1&Category_Code=category_a&Store_Code=store1&fb=1
I'm trying to use htaccess to recreate the url like this:
https://www.somedomain.com/mm5/mch.mvc?Screen=PROD&Product_Code=pcode1
I've come up with this but of course it isn't working. I think I just need to be able to ignore the rest of the url parameter after the product_code param but not sure how to do it.
RewriteCond %{REQUEST_FILENAME} !-s
RewriteRule ^Screen=PRODFB&Product_Code=([^/.]+)$ /mm5/mch.mvc?Screen=PROD&Product_Code=$1 [R=301,L,NE]
What am I missing? Thanks!
You cannot match query string in RewriteRule directive.
As long as query parameters are same as what you have in question, you may use this rule in your site root .htaccess:
RewriteEngine On
RewriteCond %{THE_REQUEST} /(mm5/mch\.mvc)\?.*&Screen=PRODFB&(Product_Code=[^\s&]+) [NC]
RewriteRule ^ /%1?Screen=PROD&%2 [R=301,L,NE]
Or using %{QUERY_STRING}:
RewriteCond %{QUERY_STRING} (?:^|&)Screen=PRODFB&(Product_Code=[^&]+) [NC]
RewriteRule ^mm5/mch\.mvc/?$ %{REQUEST_URI}?Screen=PROD&%1 [R=301,L,NE]
I was able to get it work like this:
RewriteCond %{QUERY_STRING} Screen=PRODFB&Product_Code=([^&]+)
RewriteRule ^(.*)$ /mm5/mch.mvc?Screen=PROD&Product_Code=%1& [R=301,L,NE]

Moving using 301 in htaccess using GET variables

What am I doing wrong?
I have
http://www.site.com/shop/viewmy/?ASIN=234FhK3
http://www.site.com/shop/viewmy/?ASIN=423ZH3
Trying to convert to
http://www.site.com/shopping/234FhK3/moved
http://www.site.com/shopping/423ZH3/moved
I'm going to change the "moved" part with an internal redirect after I get some info about the product 234FhK3 , a variable that changes.
I have tried
RewriteCond %{QUERY_STRING} ASIN=([^&]+) [NC]
RewriteRule ^[^/]+/(shopping/)/?$ $1.(/moved)? [L,R=301,NC]
I'm not too good with htaccess rewrites.
Try this:
RewriteCond %{QUERY_STRING} ASIN=([^&]+) [NC]
RewriteRule ^shop/viewmy/$ /shopping/%1/moved/? [L,R=301,NC]

Simple htaccess redirect - subdomain to folder

I am trying to redirect http://[random-string].domain.com/ to http://domain.com/folder/[random-string]/
I currently have this:
RewriteCond %{HTTP_HOST} ^.*\.domain\.com
RewriteRule ^.*$ http://domain.com/folder/$1/ [R=301,L]
It currently points to http://domain.com/folder//. (The $1 is missing) How do I fix this?
You need to use parenthesis to grab the value matched, in your case:
RewriteCond %{HTTP_HOST} ^(.*)\.domain\.com
RewriteRule ^(.*)$ http://domain.com/folder/%1/$1 [R=301,L]
assuming you also want to redirect http://[random-string].domain.com/something to http://domain.com/folder/[random-string]/something
how i fix it?
my subdomain not is randomically
have where the replace for $1 ?
cheers
RewriteCond %{HTTP_HOST} ^(.).domain.com
RewriteRule ^(.)$ http://domain.com/folder/%1/$1 [R=301,L]

Help with .htaccess RewriteRule. Need to take user from one URL to other

I want users who type
http://www.example.com/word-of-the-day
to be taken to
http://www.example.com/index.php?page=word-of-the-day
But I want
http://www.example.com/word-of-the-day
to be shown in the URL for the user.
What should I do in my .htaccess? I tried but the regular expression
and the syntax of RewriteRule is way too complicated for me to
figure out how to do it.
Any help will be appreciated.
Edit:
Also, how can I say this in htaccess -
if they type http://www.example.com/word-of-the-day, take them to http://www.example.com/index.php?page=word-of-the-day
or if they type http://www.example.com/something-else, take them to http://www.example.com/index.php?page=something-else
or else, just take them to the URL they typed.
The condition below checks that index.php is not being requested. If not apply the rule. This will work for any of the scenarios you listed above.
RewriteCond %{QUERY_STRING} ^!.*[index\.php].*$ [NC]
RewriteRule ^(.*)$ index.php?page=$1 [L]
In response to your comment about only wanting to do this for a few specific pages, it would look like this(as an alternative to Nils edit):
RewriteCond %{QUERY_STRING} ^!.*[index\.php].*$ [NC]
RewriteCond %{REQUEST_URI} ^word-of-the-day$ [OR]
RewriteCond %{REQUEST_URI} ^something-else$ [OR]
RewriteCond %{REQUEST_URI} ^even-something-else$
RewriteRule ^(.*)$ index.php?page=$1 [L]
Try this
RewriteEngine on
RewriteRule ^word-of-the-day$ index.php?page=word-of-the-day
Or more flexible
RewriteEngine on
RewriteRule ^(.*)$ index.php?page=$1
Not tested, yet it sould work.
To your edit:
Just define those specific URLs manually:
RewriteEngine on
RewriteRule ^word-of-the-day$ index.php?page=word-of-the-day
RewriteRule ^word-some-example$ index.php?page=some-example
RewriteRule ^some-other$ index.php?page=some-other

Resources