I have a blog under example.com/blog, but now I changed to blog.example.com, which redirects to the same old folder.
I don't want users to access directly the old URL, so, redirecting /blog to blog. How can I do it?
I would prefer using .htaccess. Current is WordPress default:
# 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
You can try this
RewriteRule ^blog/(.*)$ http://blog.example.com/$1 [R=301,L]
or
You could do something like this that would check from the main domain - This checks if you are already at blog.example.com otherwise it will redirect.
RewriteCond %{HTTP_HOST} !^blog\.example\.com$ [NC]
RewriteRule ^blog/$ http://blog.example.com [L,NC,R=301]
Related
The url gets redirected to https://2day.news/ instead of https://www.2day.news/.
This happens on every browser/mobile, cleared caches. I don't think this has anything to do with a server back-up as it goes blank when I change the redirect to a page that doesn't exist.
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^2day.news [NC]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.2day.news/$1 [R=301,L]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Add 301, www and https after RewriteBase
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\.2day\.news$ [NC]
RewriteRule ^(.*)$ https://www.2day.news/$1 [L,R=301]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
On some servers, redirecting from non-www to www in the .htaccess will cause Too many redirections error. So I recommend changing the siteurl in the database.
You can change the URL of the site in the wp_options table, in the option_value column of the following options: siteurl, home.
Or alternatively in the WP admin, under Settings > General (Wordpress URL and Site URL).
You need to add the www. prefix for both options.
Please note:
Both records should be the same (or some functions may not work because of cross-domain issues)
You need to login again to WP admin after the changes
Pages on our WordPress site are not automatically redirecting to the HTTPS version even though we have set the site url and home url to use HTTPS.
This is the code we have at the top of our wp-config.php file:
define('WP_HOME','https://webwisemedia.co.uk');
define('WP_SITEURL','https://webwisemedia.co.uk');
define('FORCE_SSL_ADMIN', true);
Our .htaccess file looks like this:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{SERVER_PORT} !^443$
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
If you visit a page on our site, like http://webwisemedia.co.uk/web-wise-in-the-press/, it doesn't redirect to the HTTPS version.
Any ideas why?
You mixed up the Wordpress part of .htaccess and that is why it isn't working. That part is changed every time you update, for example, permalinks. Your .htaccess should look like this:
# Rewrite HTTP to HTTPS
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*) https://%{SERVER_NAME}/$1 [R,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
This leaves the Wordpress part intact and it forces to use https. From now on if you change anything in .htaccess do it below the Wordpress part.
I have a wordpress website somewebsite.com
If I visit it naked like that, it works brilliantly, however if I visit it from www.somewebsite.com I get
Warning: Cannot modify header information - headers already sent by (output started at /home/somewebsite/public_html/index.php:2) in /home/somewebsite/public_html/wp-includes/pluggable.php on line 1121
In the wordpress website general settings it's set to somewebsite.com
and in CPANEL I have the following
an A record with somewebsite.com pointing to the ip address
a CNAME record with www.somewebsite.com pointing to somewebsite.com
Just for kicks I changed the setting in the wordpress general settings to www.somewebsite.com which fixed it for if I was to visit it with the www but broke it for the naked domain, so I switched it back.
my .htaccess looks like
# 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
Any help would be greatly appreciated
Simple is best :-) Redirect non-www to www or www to non-www using .htaccess, so user is going to be redirected before loading any script in php.
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
In your example:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
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>
Remember to change chmod for .htaccess - it can be overwritten by WordPress in some cases.
We had several domains parked on top of our main website. This was a normal HTML website and we used the following redirect so that the domain would 301 redirect to the proper url to avoid getting dinged by Google.
rewriteCond %{HTTP_HOST} ^ourmainsiteurl\.com$
rewriteRule ^.*$ http://www.ourmainsiteurl.com%{REQUEST_URI} [R=permanent,L]
So the above htaccess code just rewrites the url to www.ourmainsiteurl.com, which is what we want.
Now here's the problem... we installed Wordpress and it has the following default htaccess code:
# 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
I tried to add my redirect code in but that broke Wordpress. Can anyone tell me what I need to use to make this work?
Simply put I want all the parked domains (ie: parkedurl1.com, parkedurl2.com, etc) to be redirected to www.ourmainsiteurl.com with the htaccess file.
Make sure the redirect is before any wordpress rules:
rewriteCond %{HTTP_HOST} ^ourmainsiteurl\.com$ [NC]
rewriteRule ^.*$ http://www.ourmainsiteurl.com%{REQUEST_URI} [R=permanent,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
If it's still not working, check to see if wordpress has something turned on that is redirecting, or adding/removing the "www" from the hostname.
I am looking to write 301 redirects for a site. I would like the redirect to go from http://www.ehlconsulting.com/our-services-basic-services/ to http://www.ehlconsulitng.com/services/.
My .htaccess file is as follow
RewriteEngine On
RewriteCond %{HTTP_HOST} ^ehlconsulting.com
RewriteRule (.*) http://www.ehlconsulting.com/$1 [R=301,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
Redirect 301 /our-services-basic-services/ http://www.ehlconsulting.com/services/
When you go to the old URL it doens't redirect. Instead it shows "Bots get the naked version"
You probably don't want to use Redirect and want to move the actual redirect above your wordpress rules:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^ehlconsulting.com
RewriteRule (.*) http://www.ehlconsulting.com/$1 [R=301,L]
RewriteRule ^our-services-basic-services/(.*)$ http://www.ehlconsulting.com/services/$1 [L,R=301]
# 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
The "Bots get the naked version" thing doesn't have to do with your rules, it's probably WPEngine or something that's doing that by default, and you might be able to override that by using a ErrorDocument 404 in your htaccess file. The problem with using a Redirect along with wordpress' RewriteRule's is that they conflict with each other.