Get link and Redirect with Htaccess - .htaccess

i have website with this domain example.com and have file like this example.com/example.php how to redirect all file to other website there have same domain name but different in extension
so it will redirect example.com/example.php to example.net/example.php with htaccess?
Thanks so much!

Try this:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !newdomain.com$ [NC]
RewriteRule ^(.*)$ http://newdomain.com/$1 [L,R=301]

Related

Https Subdomain Redirect to Http root domain

Hello I have a subdomain
Https://apple.example.com
That I want to redirect to
Http://example.com
I tried to write on htaccess of the subdomain this code that I have found on some old question but it's not working
RewriteEngine on
RewriteCond %{HTTP_HOST} ^subdomain\.yourdomain\.com
RewriteRule ^(.*)$ http://www\.yourdomain\.com/subdomain/$1 [L]
Any help thanks
Try this instead:
RewriteEngine on
RewriteCond %{HTTP_HOST} =apple.example.com
RewriteRule ^ http://example.com%{REQUEST_URI} [R=301,L]

.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 permanent redirect of shared host subdomain

I have domain like:
someword.com.s123234.gridserver.com
I am trying to .htaccess redirect like
RewriteEngine on
RewriteCond %{HTTP_HOST} !^someword.com.s123234.gridserver.com/$
RewriteRule ^/(.*)$ http://www.someword.com/$1 [R=301,L]
but the redirect is not working.
How can I permanently redirect this type of domain?
Thank you
Since the point means something to htaccess (namely "all characters), you have to write . instead.
RewriteEngine on
RewriteCond %{HTTP_HOST} !^someword\.com\.s123234\.gridserver\.com$
RewriteRule ^/(.*)$ http://www.someword.com/$1 [R=301,L]

htaccess redirect .co.uk to .com for all pages

Im migrating my website from the .co.uk to the .com but need to setup a 301 redirect so all of the individual pages will still be routed properly.
ie i want http://www.mydomain.co.uk/shopping/product1 to go to http://www.mydomain.com/shopping/product1
I have done this before but for the life of me cannot remember how.
many thanks
paul
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.)?mydomain\.co\.uk$ [NC]
RewriteRule ^(.*)$ http://www.mydomain.com/$1 [R=301,L]
This redirects both the www and non-www for mydomain.co.uk to www.mydomain.com.
To redirect any (sub-)domain other than mydomain.com, use
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^mydomain.com$ [NC]
RewriteRule ^(.*)$ http://mydomain.com/$1 [L,R=301]
Might be useful if you have other domains pointing to the same website.
It also redirects the www.mydomain.com to mydomain.com.
This is accomplished using a simple rewrite placed in your .htaccess file.
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^mydomain.co.uk$ [NC]
RewriteRule ^(.*)$ http://mydomain.com/$1 [L,R=301]

Redirect and rewrite file to subdomain

Our site have this url
http://mydomain.com/blog.php?id=50
and need redirect its by 301 to
http://blogs.mydomain.com/blog.php?id=50
must create sub domain or folder or can we do it directly .htaccess file ?
Try the following in your .htaccess file
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^mydomain\.com [NC]
RewriteCond %{QUERY_STRING} ^id=([0-9]+)$
RewriteRule ^blog\.php$ http://blogs.mydomain.com/blog.php?id=%1 [L,R=301]

Resources