I am helping someone with their site and they want a template page (example.com/template) shown on each of their subdomains.
So when a user navigates to a.example.com or b.example.com, etc.they see example.com/template.php but the url stays a.example.comor b.example.com, etc.
I know there is a way to do this I just can't figure it out.
Basically I want to be able to change all of the pages at once by making a change to 1 file.
I think I am close with this code but I keep get 500 errors
RewriteCond %{HTTP_HOST} ^$.example.com$ [NC]
RewriteRule ^$ $1.example.com/template.php
PS: these are actual domains, not virtual
This is what I currently have
RewriteEngine On
RewriteCond %{HTTP_HOST} ^.+\.dfwfamilylifenews\.com [NC]
RewriteRule ^$ /template.php [L]
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Firstly, make sure the rewrite module is loaded in Apache. See this answer for more info.
Second, you need to change your rules to:
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^.+\.example\.com [NC]
RewriteRule ^$ /template.php [L]
Related
I have two domains, autodromodifranciacorta.it and franciacortacircuit.com both pointing to the same website hosted on this IP address: 94.23.64.40.
Now i want all the content to be under one single domain, so i decided to 301 redirect all the traffic from franciacortacircuit.com to autodromodifranciacorta.it
Here is my .htaccess file:
# BEGIN WordPress
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
# Redirect Entire Site to New Domain
RewriteCond %{HTTP_HOST} ^franciacortacircuit\.com$ [NC]
RewriteCond %{HTTP_HOST} ^www\.autodromodifranciacorta\.it$ [NC]
RewriteRule ^(.*)$ http://autodromodifranciacorta.it/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
The redirect is not working and i have no clue why, because the syntax looks correct to me.
The .htaccess file is processed, because if i put a typo in it, i get server error.
Wha'ts wrong with it?
Your second http_host condition is wrong and it never matches if the current host is franciacortacircuit.com, You need to use an OR condition to match against 2 diffrent hosts.
#Redirect Entire Site to New Domain
RewriteCond %{HTTP_HOST} ^franciacortacircuit\.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www\.autodromodifranciacorta\.it$ [NC]
RewriteRule ^(.*)$ http://autodromodifranciacorta.it/$1 [R=301,L]
I am using following htaccess file to achieve some redirections etc:
RewriteEngine On
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteCond %{HTTPS} !=on
RewriteRule .* https://www.myurl.com/$1 [R,L]
RewriteRule ^$ /home [R=301,L]
Lately i ve added the latest line so when user visits https://www.myurl.com he gets redirected to https://www.myurl.com/home for the homepage. This works fine as wanted but i have a bad feeling that this should be written somehow better. I don't like the ^$ part but it works. How could i rewrite this?
The HTTPS part can definitely be rewritten and should come first as you're creating multiple redirects.
RewriteEngine On
Options +FollowSymlinks
RewriteBase /
#redirect all traffic looking for a domain not starting with www &
#all non-https traffic to the https://www domain
RewriteCond %{HTTPS} off
#This condition is better for analytics tracking and SEO (single subdns)
RewriteCond %{HTTP_HOST} !^www\. [OR]
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteRule ^index\.php$ - [L]
RewriteRule ^$ home [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
Since your MVC is likely using index.php to process all requests it's likely that the redirect to /home will not work unless you're visiting the website without requesting any file (the root only). If someone explicitly requests https://www.myurl.com/index.php your rule that says RewriteRule ^index\.php$ - [L] tells the site to not change anything. Since you said this is working as expected I've not changed the order.
If it doesn't work as intended, then switch the order of the rule for /home.
RewriteRule ^$ home [R=301,L]
RewriteRule ^index\.php$ - [L]
So, at the moment, my .htaccess looks a little like this:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
RewriteCond %{HTTP_HOST} ^colorspace\.am$ [OR]
RewriteCond %{HTTP_HOST} ^www\.colorspace\.am$
RewriteRule ^portfolio\/?(.*)$ "http\:\/\/i\.colorspace\.am\/portfolio$1" [R=301,L]
I want to move all the content from my root directory into a subdomain (which I've done) but I don't want the links people have to not work. www.colorspace.am/portfolio needs to redirect to i.colorspace.am/portfolio, and all the sets contained therein (ie /portfolio/YYYYMMDD) also need to be 'adjusted' on the fly (www.colorspace.am/portfolio/YYYYMMDD -> i.colorspace.am/porfolio/YYYYMMDD
NOTE: i.colorspace.am contain's 2011's content; ii.colorspace.am will contain 2012. They're two entirely different WP installs with their own respective databases. Not sure if it's relevant but..
What seems to be happening is that /portfolio is instructed to redirect to i.colorspace.am/portfolio, but for whatever reason it's ending up at i.colorspace.am
IF there's a way I can make any www.colorspace.am/folder/sub-folder redirect to i.colorspace.am/folder/sub-folder (wildcard?) ..that would be amazing. But I'd be just as happy with a single fully working redirect at this point.
NOTE: the redirect code was generated by my administration panel. I tried
Redirect /portfolio http://i.colorspace.am/portfolio
But it resulted in a 'too many redirects' error.
After the redirection from
RewriteRule ^portfolio\/?(.*)$ http//i.colorspace.am/portfolio$1 [R=301,L]
The rules
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
Is accessed again. That is the reason it's ending up at i.colorspace.am.
Add these 2 rules
RewriteCond %{HTTP_HOST} ^(?:www\.)?i.colorspace\.am$
RewriteRule protfolio -[L]
in order mentioned below.
also change (just a small optimization)
RewriteCond %{HTTP_HOST} ^colorspace\.am$ [OR]
RewriteCond %{HTTP_HOST} ^www\.colorspace\.am$
RewriteRule ^portfolio\/?(.*)$ http//i.colorspace.am/portfolio$1 [R=301,L]
to
RewriteCond %{HTTP_HOST} ^(?:www\.)?colorspace\.am$
RewriteRule ^portfolio\/?(.*)$ http//i.colorspace.am/portfolio$1 [R=301,L]
and put it inside of IfModule block in the same order mentioned below.
Have just the below in your .htaccess:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
#add these 2 lines:
RewriteCond %{HTTP_HOST} ^(?:www\.)?i.colorspace\.am$
RewriteRule protfolio -[L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteCond %{HTTP_HOST} ^(?:www\.)?colorspace\.am$
RewriteRule ^portfolio\/?(.*)$ http//i.colorspace.am/portfolio$1 [R=301,L]
</IfModule>
# END WordPress
Trying to set 301 redirect in .htaccess file and here is what i am trying to do
RewriteEngine On
RewriteCond %{HTTP_HOST} ^http://localhost/wordpress/$ [OR]
RewriteCond %{HTTP_HOST} ^localhost/wordpress/$
RewriteRule (.*)$ http://www.mysite.com/wordpress/$1 [R=301,L]
I am testing this on my local machine using WAMPP server.Though when i hit http://localhost/wordpress/ i am getting redirected to http://www.mysite.com/wordpress/ but for other URL i am not getting redirected at all.for e.g
I have this URL in my local machine http://localhost/wordpress/2010/11/shadows/ and this at the server http://www.mysite.com/wordpress/2010/11/shadows/ but when i hit this URL i am not getting redirected to respected URL on the live server ,but i am being showed same page from local machine.
Working:
http://localhost/wordpress/
=> Redirected to:
http://www.mysite.com/wordpress/
Not working
http://localhost/wordpress/2010/11/shadows/
=> Redirected to:
http://www.mysite.com/wordpress/2010/11/shadows/
As clear from URL, I am trying to do this in Wordpress.
Here is complete .htaccess file
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /wordpress/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wordpress/index.php [L]
</IfModule>
# END WordPress
RewriteEngine On
RewriteCond %{HTTP_HOST} ^http://localhost/wordpress/$ [OR]
RewriteCond %{HTTP_HOST} ^localhost/wordpress/$
RewriteRule (.*)$ http://www.mysite.com/wordpress/$1 [R=301,L]
Can any one tell me whats wrong with the redirection entry? Thanks in advance
Update
I have even tried this option
Options +FollowSymLinks
RewriteEngine on
RewriteBase /wordpress/
RewriteRule ^(.*)$ http://www.mysite.com/wordpress/$1 [L,R=301]
Did not worked.
Always you first then the others (talking about RewriteRules only, man! :D ) (and you've forgotten the QSA directive).
So here's the "clean" version of your RewriteRule:
<IfModule mod_rewrite.c>
RewriteEngine On
# BEGIN My Own rewrite rules
RewriteCond %{HTTP_HOST} ^http://localhost/wordpress/$ [OR]
RewriteCond %{HTTP_HOST} ^localhost/wordpress/$
RewriteRule (.*) http://www.mysite.com/wordpress/$1 [QSA,R=301,L]
# END My Own rewrite rules
# BEGIN WordPress
RewriteBase /wordpress/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wordpress/index.php [L]
# END WordPress
</IfModule>
If it's in a .htaccess file then try without the / like this:
<IfModule mod_rewrite.c>
RewriteEngine On
# BEGIN My Own rewrite rules
RewriteCond %{HTTP_HOST} ^http://localhost/wordpress/$ [OR]
RewriteCond %{HTTP_HOST} ^localhost/wordpress/$
# Without the / after wordpress:
RewriteRule (.*) http://www.mysite.com/wordpress$1 [QSA,R=301,L]
# END My Own rewrite rules
# BEGIN WordPress
RewriteBase /wordpress/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wordpress/index.php [L]
# END WordPress
</IfModule>
By the way this is the first time in many years that a find an "under construction" page nice!
Please tell me if it works.
%{HTTP_HOST] will contain something like localhost or www.thecolorsofmysoul.com. So your conditions will never match.
RewriteCond %{HTTP_HOST} ^http://localhost/wordpress/$ [OR]
RewriteCond %{HTTP_HOST} ^localhost/wordpress/$
and the redirecting to the external domain will never fire.
Also the first two rule act in consort to map any non-file/directory to index.php. http://localhost/wordpress/ has a regexp match string of "" so will fail the pattern "." and will fail through and will redirect with your "update". Try
Options +FollowSymLinks
RewriteEngine on
RewriteBase /wordpress/
RewriteCond %{HTTP_HOST} =localhost
RewriteRule ^.* http://www.thecolorsofmysoul.com/wordpress/$0 [L,R=301]
BTW with this base this should be in DOCROOT/.htaccess. The corresponding Wordpress rules (which shouldn't be above this redirect) are
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(?!index\.php$) index.php [L]
You don't need to repeat the base in the target and the negative lookahead assertion removes the need for the first index.php rule.
Firstly, I would like to remove the www. from my domain name
http://www.example.com => http://example.com
I would also like for certain directories to be secure (https), while the rest remain http
http://example.com/login => https://example.com/login
Obviously it needs to work for all conditions, for example if someone types in:
http://www.example.com/login => https://example.com/login
Also when people navigate away from the login page it returns to http. Currently in the .htaccess is the following which is done automatically by the software I am using and I suppose needs to be there for it to work:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* ./index.php
Any ideas on how I can achieve dream control all these things?
Thanks in advance!
===================
#Gumbo Following your advice this is my complete .htaccess
RewriteEngine On
# remove www from host
RewriteCond %{HTTP_HOST} ^www\.(.+)
RewriteCond %{HTTPS}s/%1 ^(on(s)|offs)/(.+)
RewriteRule ^ http%2://%3%{REQUEST_URI} [L,R=301]
# force HTTPS
RewriteCond %{HTTPS} =off
RewriteRule ^(login)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# force HTTP
RewriteCond %{HTTPS} =on
RewriteRule !^(login)$ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* ./index.php
Options -Indexes
Navigating to http://example/login still goes to http://example/index.php when it should go to https://example/login Do I have the order wrong?
Try these rules:
# remove www from host
RewriteCond %{HTTP_HOST} ^www\.(.+)
RewriteCond %{HTTPS}s/%1 ^(on(s)|offs)/(.+)
RewriteRule ^ http%2://%3%{REQUEST_URI} [L,R=301]
# force HTTPS
RewriteCond %{HTTPS} =off
RewriteRule ^(login|foo|bar|…)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# force HTTP
RewriteCond %{HTTPS} =on
RewriteRule !^(login|foo|bar|…)$ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
You also might want to add some additional conditions to only change the protocol on GET and HEAD requests but not on POST requests.
This code works for me:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
</IfModule>
remove www (tested):
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{HTTP_HOST} ^www\.yoursite\.com$ [NC]
RewriteRule ^(.*)$ http://yoursite.com/$1 [L,R=301]
redirect (not tested):
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{THE_REQUEST} \/login/?.*\ HTTP [NC]
RewriteRule ^(.*)$ https://yoursite.com/login [L,R=301]
After reading this all post time line i have get success for following error: My website(c4dprime.com) was attached https: in mozilla firefox browser. Google and internet explore are show domain address as http: (The real problem in firefox) I did not want https: for my domain in any browser because one unknow redirect attached with my domain by https: (Cause for this error)after Installing following plugins in wordpress,(Easy redirect for ssl).... I have told to every one do not use any low level plugins for wordpress.
Anyway! After reading many articles and tutorials at this topic via google search engine. Now i am happy to say i have solve this problem from this post tips. Remember one thing about me i am new to in this form and wordpress.
This tip is help full for me
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{HTTP_HOST} ^www\.yoursite\.com$ [NC]
RewriteRule ^(.*)$ http://yoursite.com/$1 [L,R=301]
After edit or some changes in my .htaccess file following code i have use now with solved this error.
AddHandler c4d-prime .com
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} on
RewriteBase /
RewriteRule ^$ http://www.c4dprime.com/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress