Redirect and rewrite file to subdomain - .htaccess

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]

Related

.htaccess redirect subdirectory to new domain

I need to redirect all pages under a specific folder to another domain with different sub folders
For example:
FROM: https://www.my.domain.com/user/myuser/test.png
TO: https://www.newdomain.com/all/allegato1.png
I have try many htaccess file but all not work
RewriteEngine On
RewriteCond %{HTTP_HOST} ^my.domain.com$ [OR]
RewriteCond %{HTTP_HOST} www.my.domain.com$
RewriteRule ^user/myuser/(.*) http://www.newdomain.com/all/$1 [R=301,L]
I insert my .htaccess into the dir my.domain.com/user/myuser/
How can i made this rule? Thanks for your help
Inside /user/myuser/.htaccess following rule should work:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(?:www\.)?my\.domain\.com$ [NC]
RewriteRule .* http://www.newdomain.com/all/$0 [R=301,L]

301 redirect from subdomain with subfolder to different domain

Like the title says, I need to redirect from a subdomain with a subfolder to a different domain. It's important the full url is written from the subdomain, because I have more subdomains that need redirection.
I've tried the following:
RewriteCond %{HTTP_HOST} ^sub-domain.com/en/folder/subfolder/1$ [NC]
RewriteRule ^(.*)$ http://www.newdomain.com/folder/subfolder-12602124/ [R=301,L]
But this doesnt seem to work.
I can't redirect from the root because multiple domains are on this root sadly...
Try this:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.)?mydomain\.com$ [NC]
RewriteRule ^subdirectory/?$ http://newurl.com [L,R=301,NC]
htaccess how to redirect subdirectory to external URL

Get link and Redirect with 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]

How to redirect one url to another url using .htaccess?

I am trying to redirect old url to new url but it is not redirecting.
Old url: http://domain.com/STACK/App/
New url: http://domain.com/stack-app
And my .htaccess file
Redirect 301 /STACK/App http://domain.com/stack-app
Thanks,
Try this code.
RewriteEngine on
RewriteRule http://domain.com/STACK/App/ /http://domain.com/stack-app [R=301,L]
For more help go to this link:--
http://edward-designer.com/web/htaccess-url-rewrite-simplified/
You can use this rule as your very first redirect rule in your root .htaccess:
RedirectMatch 301 ^/STACK/App/?$ /stack-app
Within the mod_rewrite section of your .htaccess file, add the following lines on the old site:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.domain\.com\STACK\App\$
RewriteRule (.*)$ http://domain.com/stack-app/$1 [R=301,L]
</IfModule>
you can use the following code to redirect your website using .htaccess
RewriteEngine On
RewriteCond %{HTTP_HOST} !oldexample.com$ [NC]
RewriteRule ^(.*)$ http://www.newexample.com/$1 [L,R=301]
for non www version, you can use the following,
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !oldexample.com$ [NC]
RewriteRule ^(.*)$ http://newexample.com/$1 [L,R=301]

(.htaccess) 301 redirect with same url structure

I use 301 redirect from non-WWW to WWW domain! Works fine, but links are different.
Example:
from - ggkj.com/posts/godzilla/43
to - www.ggkj.com/index.php?view=posts&author=godzilla&aid=43
my .htaccess 301 redirect code:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\.example\.com [NC]
RewriteRule ^(.*) http://www.example\.com/$1 [L,R=301]
.htaccess code: http://pastebin.com/t3FA59uq
This is currently what i use on my website with success:
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{http_host} !^www.walterbax.ca [NC]
RewriteRule ^(.*)$ http://www.walterbax.ca/$1 [R=301,L]
EDIT: after looking into your question a little further I can tell you that your issue is improperly placed in the file. it must be hitting another rule that is rewriting it into URL variables.
I would start with a basic htaccess for the www. rule for testing and add to it from there.
Try this:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^yourdomain.com$
RewriteRule ^(.*)$ http://www.yourdomain.com/$1 [R=301,L]

Resources