Redirect from one website to another and keep directory - html

The blog section of a website moved from a subdomain to a directory of the main domain. I need to redirect all users visiting blog.site.com to site.com/blog/ and the directory someone enters should be kept when forwarding, e.g. blog.site.com/post/welcome should point to site.com/blog/post/welcome
I treid adding this to my .htaccess file which I placed in the subdomain's directory via FTP:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^blog.herderzeitung.de$ [OR]
RewriteCond %{HTTP_HOST} ^www.blog.herderzeitung.de$
RewriteRule (.*)$ https://herderzeitung.de/blog/$1 [R=301,L]
However, this doesn't seem to be working. I was also wondering, what the most SEO friendly way is to achieve this (the site permanently moved to another domain).
Thanks in advance!

Try
RewriteEngine On
RewriteCond %{HTTP_HOST} ^blog\.herderzeitung\.de$ [OR]
RewriteCond %{HTTP_HOST} ^www\.blog\.herderzeitung\.de$
RewriteRule ^/?(.*)$ https://herderzeitung.de/blog/$1 [R=302,L]
I've escaped the dots, and anchored&normalized the pattern. Also switched it to temporary redirects (302); once you know it works, then change it to 301 again for SEO reasons.
And yes, as far as i know 301s are the best method for retaining your search rankings and the like.

This seems to work:
RewriteEngine On
RewriteCond %{REQUEST_URI} (.*)
RewriteRule ^(.*)$ https://herderzeitung.de/blog/$1 [L,R=301]
Thank you everyone!

Related

How to redirect all html files in a domain to a specific webpage?

I have 2 bluehost accounts. One belongs to a former employee and the other is our companies new one. We have several domains in the old account, like chinafabrix.com and we want all domains to redirect to our new website vitasino.com. The thing is that we dont just want chinafabrix.com to redirect but also chinafabrix.com/index.html chinafabrix.com/whatever.html chinafabrix.com/blahah.html etc etc to redirect to vitasino.com (not vitasino.com/x.html but only vitasino.com)
Is there any way of doing this without writing a separate redirect in all the html files in the domain?
RewriteEngine on
RewriteRule ^(.*)$ http://www.vitasino.com/$1 [R=301,L]
or
RewriteEngine On
RewriteRule ^(.*)$ http://vitasino.com/ [R=301]
In the site root .htaccess of your old site you can place this single catch-all rule:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(?:www\.)?chinafabrix\.com$ [NC]
RewriteRule ^(.+\.html)?$ http://vitasino.com/? [L,NC,R=301]

Need Help in my website IP Canonicalization .htaccess

i have searched the whole internet to find solution my website is www.hrxlevels.tk and ip address associated with website is this 31.170.163.33 and want the .htaccess for ip to redirect to domain
# Do not remove this line, otherwise mod_rewrite rules will stop working
RewriteEngine On
RewriteCond %{HTTP_HOST} ^hrxlevels.tk [NC]
RewriteRule ^(.*)$ http://www.hrxlevels.tk/$1 [L,R=301]
RewriteEngine On
RewriteCond %{HTTP_HOST} ^31\.170\.163\.33
RewriteRule ^(.*)$ http://www.hrxlevels.tk/$1 [L,R=301
RewriteBase /
and this code is not working for ip canonicalization but works great for url cononicalization please help please!
please use this detail and please write the .htaccess file for my website.
My webhost is 000webhost.com

modrewrite to remove the file extension but still load the page

I have a subdomain with .php pages in it. I just want to remove the .php I have written some code gathered from other posts on stack, so far I have this
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} (\.php(.*)\sHTTP/1)
RewriteRule ^(.+)\.php$ /$1 [R=301,L,QSA]
this rewrites
subdomain.example.com/weddings.php
to
subdomain.example.com/weddings
However it also creates a 404 page not found error. Am I doing something wrong?
Solved it. anyone struggling with the same thing here is my solution
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
found it on
http://css-tricks.com/snippets/htaccess/remove-file-extention-from-urls/
a fantastic website.

difference between www.xyz.com and xyz.com and how to redirect .htaccess

I have a site and am using Google Webmaster tool. I created the setting within the tool for the site twice: once as www.xyz.com and once as xyz.com. The statistics from both are different once I drill down into details.
I want to stick with www.xyz.com. How can I make everyone go to xyz.com be redirected to www.xyz.com? and will this harm my ranking or indexing in google?
regards,
sorry if the question is simple :)
with htaccess, i use the following for forced www
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www
RewriteRule (.*) http://www.%{HTTP_HOST}/$1 [L,R=301]
although you might be best doing the following if if it is for SEO purposes
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www
RewriteRule (.*) http://www.%{HTTP_HOST}/$1 [L,R=301]
RewriteCond %{THE_REQUEST} ^.*/index.php
RewriteRule ^(.*)index.php$ http://%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{THE_REQUEST} ^.*/index.htm
RewriteRule ^(.*)index.htm$ http://%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{THE_REQUEST} ^.*/index.html
RewriteRule ^(.*)index.html$ http://%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{THE_REQUEST} ^.*/home.htm
RewriteRule ^(.*)home.htm$ http://%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{THE_REQUEST} ^.*/home.html
RewriteRule ^(.*)home.html$ http://%{HTTP_HOST}/$1 [R=301,L]
as this also removes any index or home page part of the url.
in webmaster tools in settings, you can also select always use www, which will merge the data for both domains under a single www domain (although you will be able to see both www and non-www listed in GWMT)
Use preffered domain, more instructions here:
http://support.google.com/webmasters/bin/answer.py?hl=en&answer=44231
Specify a preferred domain:
On the Webmaster Tools Home page, click the site you want.
Under Site configuration, click Settings.
In the Preferred domain section, select the option you want.
You could also use 301 redirect:
http://support.google.com/webmasters/bin/answer.py?hl=en&answer=93633

.htaccess redirect

Just wondering if someone can help me with the following issue.
I want to redirect my site to a subdomain, whishc simply displays a maintenace page, allowing me to work on the main site.
So I have the following code for my .htaccess:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain.co.uk$ [OR]
RewriteCond %{HTTP_HOST} ^www.domain.co.uk$
RewriteRule ^/?$ "http\:\/\/maintenance\.domain\.co\.uk" [R=301,L]
However, I need to access the root domain to be able to view the work that I have done; however, I only want myself on my IP to be able to view that and the outside world is redirected to the subdomain which displays the maintenace page.
I would have thought that the following code:
RewriteCond %{REMOTE_HOST} !^00\.000\.00\.000
Would have allowed me to do that; however, I'm still being redirected to the sub domain and I wondered is someone could assist me further wth this.
Thanks
You'd be better of using %{REMOTE_ADDR}, I believe:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.co\.uk$ [NC]
RewriteCond %{REMOTE_ADDR} !=00.00.00.00
RewriteRule ^/?$ http://maintenance.domain.co.uk/ [R=301,L]