I want to allow the users to type
xyz.example.com
in order to reach
test.php?id=xyz
What code should I use to accomplish my goal?
Try adding the following to your htaccess file in the root directory of your example.com domain
RewriteEngine on
RewriteBase /
#if the host is anything.example.com
RewriteCond %{HTTP_HOST} ^([^\.]+)\.example\.com$ [NC]
#send all requests to test.php
RewriteRule .* test.php?id=%1 [L]
Related
I want to 301 redirect a subdomain to another domain with htaccess.
I want:
A: www.subdomain.domain1.se
B: subdomain.domain1.se
C: subdomain.domain1.se/anything/anything.anything#anything?anything
to redirect to:
A: www.domain2.se
B: www.domain2.se
C: www..domain2.se/anything/anything.anything#anything?anything
Also I need to know where to put the file (in subdomain directory or root directory). Best would be if I could put the htaccess file in the subdomain ddirectory if possible.
I have tried this:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^c\.domain1\.se$ [NC]
RewriteRule ^(.*)$ http://www.domain2.se/$1 [QSA,R=301,L]
I think you messing RewriteBase / in the code
regular redirect 301 work like this
RewriteEngine On
RewriteBase /
RewriteRule ^(.*)$ http://domain2.com/$1 [L,R=301,NC]
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteCond %{HTTP_HOST} subdomain\.domain1\.se$ [NC]
RewriteRule ^ http://www.domain2.se%{REQUEST_URI} [R=301,L,NE]
Reference: Apache mod_rewrite Introduction
However note that URL part after hash is not sent to web server hence cannot be handled by Apache mod_rewrite.
I'm looking to redirect my domain example.com and www.example.com to http://example2.com, but I want to keep all visits to my posts at http://example.com/sdfhs to continue through to their destinations.
Essentially, I ONLY want to redirect the root and www domain and leave the rest untouched.
How can I do this with .htaccess?
Don't know if you still have this issue, but I have had it on one of my domains (Yourls installation). Try:
RewriteEngine On
RewriteRule ^$ http://www.example.com/ [R=301,L]
It works on my installation, but check it out on your site.
Why not
RewriteEngine On
RewriteCond ${HTTP_HOST} example\.com|www\.example\.com
RewriteRule ^/?$ http://example2.com [L]
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond ${HTTP_HOST} ^(www\.)?example\.com$ [NC]
RewriteRule ^$ http://example2.com [L,R=301]
You could simply match any URL with at least 1 character (.+) and mark that as the last rule for the rewrite engine to look at [L].
Then afterwards redirect anything else (.*) to the new domain (the only other thing that wouldn't be matched up to that point would be the root).
RewriteEngine On
RewriteRule ^(.+)$ - [L]
RewriteRule ^(.*)$ http://example2.com/$1 [R=301,L]
I want to do the following, if possible, with htaccess.
The webpage works this way, you get the index file via domain.de/de/start and the english version via domain.de/en/start.
If a user visits domain.com I would like him to end up at domain.de/en/ instead of domain.de/de/ so I need to rewrite all requests to domain.com but NOT requests with domain.com/xx/something to domain.de/en/
Thanks.
If I understand you clearly you only want to redirect http://domain.com/ to http://domain.de/en/ but do NOT want to redirect http://domain.com/XX/YY
Put this code in your .htaccess:
Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain\.com$
RewriteRule ^$ http://domain.de/en/ [L,R=301]
Try to use HTTP_HOST and rewritecond
RewriteCond %{HTTP_HOST}=domain.de
RewriteCond %{REQUEST_URI}=/ % redirect only the root
RewriteRule ^/$ /de/start [L] % to /de/start
RewriteCond %{HTTP_HOST}=domain.de
RewriteCond !%{REQUEST_URI}=/ % no root
RewriteCond !%{REQUEST_URI}=/[a-z]{2}/.* % except /xx/ directories
RewriteRule ^/.*$ /de/$1 [L] % push the user in the /de/ directory
for example
mydomain.com/jobresultpage?what=&where=Arkansas
redirect to
yourdomain.com/jobresultpage?what=&where=Arkansas
but other page like
mydomain.com/about.html
mydomain.com/contact.html
not redirect..
Try adding the rules below to the .htaccess file located in the root directory of mydomain.com
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} mydomain\.com$ [NC]
#redirect any request for jobresult to yourdomain
RewriteRule ^jobresultpage$ http://yourdomain.com%{REQUEST_URI} [NC,L,R=301]
My server is somehow configured to accept any string as a existing subdomian. This subdomains doesn't redirect, they show content instead. For example:
bla.example.com // shows the content of http://example.com
blabla.example.com // show the content of http://example.com
lorem.example.com/events/ // shows the content of http://example.com/events
So you can use "stackoverflow.example.com" and it will work.
I want to create an .htaccess rule to overwrite this behavior. I want to redirect http://*.example.com/* to http://www.example.com/*
Everything I have done so far is redirect http://example.com to http://www.example.com (wich is another behavior I want to keep)
RewriteCond %{HTTP_HOST} ^example\.com$
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
Thank you for your help!
Try adding the following to your htaccess file in the root folder of your domain
RewriteEngine on
RewriteBase /
#if its not www.example.com
RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
#redirect it to www.example.com
RewriteRule .* http://www.example.com%{REQUEST_URI} [R=301,L]