redirect subdomain to folder without changing url - apache

I want to redirect the www.domain.com to the www folder without changing the url in the address bar (internal redirect), I tried and used the following code but it's not working
I do this to organize my public_html folder
the .htaccess file is in the public_html folder
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www)\.domain\.com
RewriteRule ^(.*)$ /www/$1 [L]

Try this rule
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www)\.domain\.com$ [NC]
RewriteRule !^www/ /www%{REQUEST_URI} [L,NC]

Related

.htaccess let subdomain behave as main domain

I would like to create subdomain just for one page of main domain. I don't want to have copy of files so i try to solve it using mod_rewrite.
Simply when i go to submdomain.domain.com i want to show page xyz.html as index.html with all pictures. The mod rewrite should keep address in browser url as subdomain.domain.com
RewriteEngine On
RewriteCond %{HTTP_HOST} ^subdomain.domain.com
RewriteCond %{REQUEST_URI} !(index.html)
RewriteRule ^(.*) http://www.domain.com/$1 [P,L]
RewriteCond %{HTTP_HOST} ^subdomain.domain.com
RewriteCond %{REQUEST_URI} index.html
RewriteRule index.html http://www.domain.com/xyz.html [P,L]
this .htaccess is saved in subdomain of root directory. Unfortunately it works only separatly. First half works only when second half is missing and vice versa. So i am able to do redirect to show only xyz.html page as index page but without images, or do redirect for all subdomain files but xyz.html is ignored and main domain index.html is used.
at the end i have found the solution
RewriteEngine On
RewriteCond %{HTTP_HOST} ^subdomain.domain.com
RewriteCond %{REQUEST_URI} index.html
RewriteRule index.html http://www.domain.com/myspecial-page.html [P,L]
RewriteCond %{HTTP_HOST} ^subdomain.domain.com
RewriteRule ^([a-zA-Z0-9\.\-\_]+).html$ http://www.domain.com/$1.html [NC]
RewriteCond %{HTTP_HOST} ^subdomain.domain.com
RewriteRule ^images/([a-zA-Z0-9\.\-\_]+)$ http://www.domain.com/images/$1 [NC,P]
etc...for css, js
it is possible to test rules using htaccess tester

.htaccess: How can I keep the redirection and remove the subdirectory path from the urls please?

I am trying to direct traffic to a subdirectory using .htaccess
The subdirectory is: /Release2/code.
The following is successfully redirecting but its is not hiding /Release2/code from the urls
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?mysite\.com$
RewriteCond %{REQUEST_URI} !^/Release2/code
RewriteRule ^(.*)$ /Release2/code/$1 [L]

.htaccess redirect with folder and file exception

I'd like to only redirect http://www.website.com/ to https://www.newsite.com.br/website
Except all files and directories like:
http://www.website.com/admin
http://www.website.com/img/image.png
http://www.website.com/cliente
And any URL different then http://www.website.com/ should not redirect
You can use this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.)?website\.com$ [NC]
RewriteRule ^/?$ https://www.newsite.com.br/website/ [R=301,NE,L]

.htaccess if subdomain show www.site.com/subs/. no redirect url must bu sub.site.com

I have problem with .htaccess.
I need:
if $_SERVER["HTTP_HOST"] is sub.site.com must show content from www.site.com/sub/. But URL must be like sub.site.com.
And if sub.site.com/content/ must show content from www.site.com/sub/content/
Is it Possible?
Setting subdomains from hosting not working for me because of my CMS.
Try adding these rules to the htaccess file in your document root:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^sub.site.com$ [NC]
RewriteCond %{DOCUMENT_ROOT}/sub%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}/sub%{REQUEST_URI} -d
RewriteRule ^(.*)$ /sub/$1 [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} ^sub\.site\.com$ [NC]
RewriteRule (?!^sub/)^(.*)$ /sub/$1 [L,NC]

redirect *.exapmle.com/foo/bar?moo=soo to exapmle.net/foo/bar?moo=soo

i want redirect all request to
*.exapmle.com/foo/bar?moo=soo TO exapmle.net/foo/bar?moo=soo
for example
www.exapmle.com/foo/bar?moo=soo TO exapmle.net/foo/bar?moo=soo
or
exapmle.com/foo/bar?moo=soo TO exapmle.net/foo/bar?moo=soo
how do it with htaceess file?
how i redirect [wildcard].exapmle.com/[wildcard2] to example.net/[wildcard2] for example s1.example.com/content/1?from=test to example.net/content/1?from=test
Add the following to the .htaccess file in the root directory of your exapmle.com site
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} exapmle\.com$ [NC]
RewriteRule ^ http://exapmle.net%{REQUEST_URI} [L,R=301]