.htaccess redirect with folder and file exception - apache

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]

Related

htaccess redirect everything inside folder to no-www

I need to redirect a specific folder and ALL of it content from "www.domain.com/myfolder/" to "domain.com/myfolder/". That folder contains more folders.
I've tried including this .htaccess file to the folder, with no success.
Options +FollowSymlinks -Indexes -MultiViews
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^www.domain.com [NC]
RewriteRule (.*) http://domain.com/myfolder/$1 [R=301,L]
But only redirects "www.domain.com/myfolder/" to "domain.com/myfolder/".
If I access to "domain.com/myfolder/something/" (index of something folder) or "domain.com/myfolder/something/whatever" (file inside something folder) isn't working, it throws 404 error.
Maybe using some regex?
You can use the following rule
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.domain\.com [NC]
RewriteRule ^folder/ http://domain.com%{REQUEST_URI} [NE,L,R]

redirect subdomain to folder without changing url

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]

.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]

.htaccess RewriteRule redirect

i need help redirecting this two links to one link:
Link #1: http://www.domain.com/index.php?til=d_news&id_new=1
Link #2: http://www.domain.com/new_folder/?til=d_news&id_new=1
need to redirect to:
http://www.domain.com/news/news.html
i tried using this code:
RewriteCond %{QUERY_STRING} ^til=d_news
RewriteRule ^(.*)$ http://%{HTTP_HOST}/news/news.html? [R=301,L]
but it only redirects the first link and not the second.
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 %{QUERY_STRING} ^til=d_news&id_new=1 [NC]
RewriteRule ^ /news/news.html? [R=301,L]
In the htaccess file in your document root, add:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^til=d_news&id_new=1
RewriteRule ^index.php$ /news/news.html? [L,R=301]
RewriteCond %{QUERY_STRING} ^til=d_news&id_new=1
RewriteRule ^new_folder/?$ /news/news.html? [L,R=301]
In your second link there is no destination page:
http://www.domain.com/new_folder/?til=d_news&id_new=1
should be something like:
http://www.domain.com/new_folder/page.php?til=d_news&id_new=1

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]