How to setup addon domain .htaccess - .htaccess

I'm trying to setup a rule in the .htaccess file to allow me to add the 'something' to my website url, like this: something.mywebsite.com redirect to some subdirectory.
I have other rewrite conditions inside my .htaccess file already
Can you do this via .htaccess?

RewriteBase /
RewriteCond %{HTTP_HOST} ^subdomain.domain.com$ [NC]
RewriteRule ^(.*)$ http://domain.com/somesubdomain [R=301,L]

Related

How to rewrite url in htaccess to hide subfolder?

My website is located in a subfolder (gng2) of my public_html folder. The below code from the public_html/.htaccess file works fine in the sense that typing my domain loads the website properly from the subdirectory:
## redirect to subfolder containing the app.
RewriteCond %{HTTP_HOST} ^example.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www.example.com$
RewriteCond %{REQUEST_URI} !gng2/
RewriteRule (.*) /gng2/$1 [L]
My problem is that www.example.com/gng2/whateverpage also works. I want to rewrite/reroute these urls to www.example.com/whateverpage so that the "gng2" subfolder does not show up for example in Google Analytics results.
How should I modify the above code to achieve this?
Thanks,
W.
You can use this redirect rule in gng2/.htaccess to remove /gng2/ from all URLs:
RewriteEngine On
RewriteCond %{THE_REQUEST} \s/+gng2/(\S*) [NC]
RewriteRule ^ /%1 [L,R=301,NE]
# other rules appear below this line
Please keep your htaccess file inside gng2 folder and try following rules in your htaccess rule file. Please make sure these rules are at top of your file(for applying http/HTTPS to URLs, in case you have more rules), also please do clear browser cache before testing your URLs.
RewriteEngine ON
## redirect to subfolder containing the app.
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC]
##Place your RewriteRule here.....

htaccess for subdomain no longer in use

I had a subdomain https://sub.rootdir.com/ which was migrated to the root domain and to a new host.
I want to redirect this subdomain to the root folder. The host told me to re-create the subdomain and then create an '.htaccess' file in which you can set redirection rules such as:
Redirect 301 / https://rootdir.com/
I have kind of no idea what to type in the htaccess file.
Can I please get help from you?
Create a .htaccess file in your subdomain folder and enter this code in;
RewriteEngine On
RewriteCond %{HTTP_HOST} !^rootdir\.com
RewriteRule (.*) https://rootdir.com/$1 [R=301,L]
I figured it out from other posts here tx
#mod_rewrite on
RewriteEngine On
RewriteCond %{HTTP_HOST} ^sub.rootdir.com$ [NC]
RewriteRule ^(.*)$ https://www.rootdir.com%{REQUEST_URI} [R=301,NC,L,QSA]

Redirect site .htaccess

How to redirect this
https://www.example.com/watch?v=ilTNJoSgeF8
to this
http://www.example.com/#/watch/ilTNJoSgeF8
so it just need to change this /watch?v= into this /#/watch/
Using mod_rewrite, you can do something like this in the htaccess file in your document root:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^v=([^&]+)
RewriteRule ^watch$ /#/watch/%1? [L,NE,R]

301 redirect subdomain to another domain with htaccess

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.

Redirect specific page with query using htaccess

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]

Resources