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]
Related
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]
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]
i want to replace a word from url. i try many code but. not working
RewriteRule ^(.*)/resetter/(.*)$ $1/reseter-de-puces/$2 [L]
i want to redirect
catalogue-encros/resetter/epson/resetter-pour-epson-ancienne-génération/8345-37457
to
catalogue-encros/reseter-de-puces/epson/resetter-pour-epson-ancienne-génération/8345-37457
i have added www redirect which is work fine
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
You are missing a / before the $1, try:
RewriteRule ^(.*)/resetter/(.*)$ /$1/reseter-de-puces/$2 [L]
Without the / before $1 your would url would have turned into something like:
http://domain.com/www/var/home/domain.com/somedirectory/reseter-de-puces/
I want to remove the slash of 1 and only 1 url
this snippet will remove them all
# Remove the trailing slash
RewriteCond %{HTTP_HOST} ^(www.)?example\.com$ [NC]
RewriteRule ^(.+)/$ http://www.example.com/$1 [R=301,L]
but i just want to change
example.com/changeme/
to
example.com/changeme
any ideas how to change this htaccess i have to only do it on one
You could replace (.+) with (changeme) in RewriteRule:
RewriteRule ^(changeme)/$ http://www.example.com/$1 [R=301,L]
This will only match 'changeme' and not everything.
In this way you can also match multiple URLs, including e.g. 'changeother' and 'foobar':
RewriteRule ^(changeme|changeother|foobar)/$ http://www.example.com/$1 [R=301,L]
How about this?
RewriteRule ^changeme/$ http://www.example.com/changeme [R=301,L]
All you need is (as long as this rewrite is only applied to example.com):
RewriteRule ^changeme/$ changeme [R=301,L]
I am looking to make www.purchase.example.com redirect to purchase.example.com, below is an example of what I am trying to do:
RewriteCond %{HTTP_HOST} ^www\.purchase\.
RewriteRule (.*) http://purchase.DOMAIN_NAME/$1 [L,R]
I need a variable that will replace DOMAIN_NAME with simply purchase.example.com.
Obviously I can hard code the purchase.example.com but I will need the code to work on multiple sites. Any suggestions?
For your knowledge:
I used a RewriteCond backreference:
RewriteCond %{HTTP_HOST} ^www\.purchase\.(.*)
RewriteRule (.*) http://purchase.%1/$1 [L,R]
I would not do this in code, I would do this on the web hosting account.
If you need it a little more generic redirect for every domain starting with www.:
RewriteCond %{HTTP_HOST} ^www\.(.+)
RewriteRule ^ http://%0%{REQUEST_URI} [L,R=301]