how to redirect example.com with htaccess - .htaccess

how to redirect example.com to example.com/market using .htaccess file
ex.
http://example.com/details.php?id=3667 and
http://www.example.com/details.php?id=3667
should redirected to
http://example.com/market/details.php?id=3667
and also I want to redirect any example.com to example.com/market
using htaccess

According to here for:
Redirecting www to non-www
RewriteEngine On
RewriteCond %{HTTP_HOST} !^example\.com$ [NC]
RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]
Redirect root to subfolder
Redirect / http://example.com/market

Related

.htaccess Redirect non-www to www and main domain to sub-folder

I want to redirect my non www domain to www and to a subfolder
I was able to redirect the domain to the subfolder with this code
RewriteCond %{HTTP_HOST} ^(www\.)?domain2\.com$ [NC]
RewriteRule !^subdir/ /subdir%{REQUEST_URI} [L,NC]
now I want to redirect my domain to www. how do I do that?
if I try to add www infront of my doman it still shows a non-www domain
You can use this :
RewriteEngine on
#redirect non-www to www
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^.*$ http://%1%{REQUEST_URI} [NE,L,R]
# rewrite /root to subfolder
RewriteCond %{HTTP_HOST} ^(www\.)?domain2\.com$ [NC]
RewriteRule !^subdir/ /subdir%{REQUEST_URI} [L,NC]

.htaccess redirection to specific url

I moved my site from blog.abc.com to www.abc.com
I want to redirect every request made to blog.abc.com to abc.com
For example:
If blog.abc.com/example.html is requested, it should redirect to www.abc.com/example.html, how can I do it via .htaccess only?
You can put this code in your htaccess (in blog.abc.com root folder)
RewriteEngine On
RewriteCond %{HTTP_HOST} ^blog\.(.+)$ [NC]
RewriteRule ^(.*)$ http://www.%1/$1 [R=301,L]
Using mod_rewrite you could do it like this:
RewriteEngine On
RewriteCondition %{HTTP_HOST} ^blog.example.com$ [NC]
RewriteRule ^(.*)$ http://example.com/$1 [R,L]
or if blog.example.com has its own vhost you could also use mod_alias:
Redirect / http://example.com/

htaccess: non-www to www but only when no subdomain is set

I want this:
domain.tld to www.domain.tld
And other subdomains: sub.domain.tld without redirect to www.sub.domain.tld
You can put this code in your htaccess (in root folder)
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain\.tld$ [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

redirect domain.com to www.domain.com with htaccess

How to redirect an 'empty' subdomain http://domain.com to http://www.domain.com using htaccess rewrite engine. It has to be a 301 permanent redirect and convey the rest of the url and query string.
Try putting these rules in the htaccess file in your document root:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain\.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301]
The query string gets automatically appended.

Redirect .com to .org in .htaccess

I have domain.com and domain.org as aliases pointing to the same vhost. How can I use .htaccess to redirect all domain.com requests to domain.org?
You could use mod_rewrite to do this.
RewriteEngine on
RewriteCond %{HTTP_HOST} !^example\.org$
RewriteRule ^ http://example.org%{REQUEST_URI} [L,R=301]
This rule redirects every request that’s not addressed to example.org to the very same.
Redirects all www/non-www of domain.com to domain.org:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.org/$1 [R=301,L]

Resources