I want to use subdomains instead of subfolders. Unfortunately, since my host doesn't allow wildcard subdomains in my dns settings, I couldn't do a subdomain install. I do however think that I should be able to achieve this post-install, since I can manually make subdomains.
I have now made two subdomains: Subdom1 and Subdom2. My set-up at this point is domain/Subdir1 and domain/Subdir2. I'd like to have my visitors (and ideally also Google) to visit my site as subdom1.domain.com and subdom2.domain.com, both should show what is in the two subdirs.
I think this should be possible with .htaccess rules, but I'm hardly the expert at that. I'm hoping someone could help me with this.
try this, obviously replace blog with your subdomain name
Options -Indexes +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http://www.example.com$1 [L,R=301]
RedirectMatch 301 ^/blog/(.*)$ http://blog.example.com/$1
more here http://terriswallow.com/weblog/2008/htaccess-redirect-a-directory-to-a-subdomain-and-force-www/
Related
A bit out of my comfort zone, hoping someone can point me in the right direction!
I need to force all http://www.mywebsite.com to go to https://sub.mywebsite.com.
So, I need to force all visitors to the sub-domain, but also the secure https version.
I've tried editing the root htaccess file but I get 'too many redirects' error.
The new site is using a Wordpress child theme in case that makes a difference - when I edited the root htaccess the site appeared unstyled and the 'too many redirects' error related to CSS and JS files.
I'm sure it's something silly and small but any help, much appreciated! :-)
Thanks
Try putting this into the htaccess file above all other existing rules:
RewriteEngine On
# First redirect to the subdomain
RewriteCond %{HTTP_HOST} ^(www\.)?example.com
RewriteRule ^(.*)$ https://sub.example.com%{REQUEST_URI} [L,R=301]
# Then ensure HTTPS
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://sub.example.com/$1 [L,R=301]
I am trying to create a permanent htaccess redirect (301) from all my domain extensions into the appropriate subdirectories. The "rules" are as follow:
Redirect belgian website to its subdirectory on the main website:
from: www.example.be
to: www.example.com/befr/
Of course I would like to preserve the url parameters (if any) of the "from". Globaly, if someone entered the first url it should redirect to the second url (langage subdirectory in the main website).
I'm using wordpress and I'm hosting on a plesk I've read many things here but I'm stuck, thank you very much in advance for your help
PS: I've tried that but it doesn't work
RewriteCond %{HTTP_HOST} ^(www\.)?example.be$ [NC]
RewriteRule ^(.*) http://www.example.com/befr/$1 [L,R]
After reading your question, your code should be working (with informations you gave).
If it's not, here are some points to check:
1. Make sure mod_rewrite is enabled and htaccess can be executed (Apache config).
2. Your htaccess has to be in root folder (where example.be is forwarded).
3. About your htaccess' code:
since you're using Wordpress, make sure your rule is on top of other rules
don't forget to escape . (second one) in RewriteCond (otherwise it doesn't mean the same) even if it works that way
replace R flag (302 by default) by R=301 if you want a 301 redirect
Your code now looks like this
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?example\.be$ [NC]
RewriteRule ^(.*)$ http://www.example.com/befr/$1 [R=301,L]
# your other rules (and Wordpress' default rule) here
I have a Wordpress site runing on Apache and now I want to add another domain adress to this site.
In a few words here... I have two domain names domain1.com and domain2.com .
domain1.com is set and the website is working as it should but now I want to add another domain for the same site. domain2.com, must be redirect to domain1.com, the problem is that I have no idea why it doesn't work, because when I try to access domain2.com it open the following address.
http://domain1.com/wp-signup.php?new=domain2.com
Basically this is a redirect to default domain on signup page. What should I do to fix this?
Hope you understood the question, I don't know how to explain it better.
Edit:
I've added the following rules in .htaccess and restarted apache, but the problem persists. Maybe is something from Wordpress?
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(.*)domain2.com [NC]
RewriteRule ^(.*)$ http://domain1.com/$1 [R=301,L]
OK, looks like all this is wordpress related and apache(htaccess) have nothing to do here. The solution that works for me:
I've added this line in wp-config.php and now it works great. Now if I access domain2.com it is redirected to domain1.com, exactly what I wanted. :)
define( 'NOBLOGREDIRECT', 'http://domain1.com' );
This is what I use for my 301 redirects:
RewriteCond %{HTTP_HOST} ^domain2.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.domain2.com$
RewriteRule ^(.*)$ "http\://www.domain1.net/$1" [R=301,L]
This redirects the domain whether or not people type in the www. part of the url. The backslashes (\) escape the punctuation.
Hope this helps.
I have a site running wordpress, it's the full site. One of the pages is like a contact-us form located at www.ourdomain.com/contact-us/
I also have a URL like contactourdomain.com and I want it to redirect to www.ourdomain.com/contact-us/
We used to do this with a redirect on network solutions, but I prefer to have it all done right on the server if possible. I've got it sort of working but when you visit the link is still says contactourdomain.com/contact-us/ as the URL, and that breaks all the other ones.
Any suggestions?
.htaccess
Options -MultiViews
RewriteEngine on
RewriteBase /
# Rewrite
RewriteRule ^(.*)$ http://www.ourdomain.com/contact-us//$1 [L]
if you add this in .htaccess is it working?:
RewriteRule ^$ contact-us/ [R=301,L]
keep me posted..
This is a really weird question and I apologize:
I've been asked if it's possible not to import our blog from Wordpress to Drupal but just keep it in Wordpress as an archive and re-direct our users say from hostname/blog/... to hostname/wordpress/... when a URL matches the Wordpress URL pattern.
I've never heard of anyone trying this and I'm wondering about pitfalls and whether or not it's even possible.
Thanks!
D
This looks like it should be pretty simple to do. I plan to take advantage of the mod_rewrite module for apache:
We will just need to configure a .htaccess file to redirect URLs matching hostname/blog/pattern/ - where pattern fits a Wordpress URL blog pattern.
I use mod_rewrite on my Drupal site. Here's an example I use to redirect users to www.earldouglas.com when they access earldouglas.com:
RewriteCond %{HTTP_HOST} ^earldouglas.com [NC]
RewriteRule ^(.*)$ http://www.earldouglas.com/$1 [L,R=301]
You could try something like the following:
RewriteCond %{REQUEST_URI} /blog
RewriteRule ^(.*)$ /wordpress [L,QSA]