I have a wordpress site, the url was www.mysite.com/name-of-the-post
But the client change to www.mysite.com/blog/name-of-the-post
Now I have a problem with the users who click on old links, they can't access the content.
How can I solve this? I've reading about and something with regular expressions on htaccess, how can I add "/blog" when the users trying to access old links?
Thanks guys
Where I will put this code? My htaccess is this:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [L,R=301,NC]
# Force HTTPS
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [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
Related
I have a domain with a working htaccess file, which redirects all http traffic to https. This is/was working all fine.
Here is that .htaccess file:
RewriteEngine on
RewriteCond %{REQUEST_URI} !\.well-known/acme-challenge
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html [NC,L]
Just now, I have installed wordpress in a sub-folder called "blogg" like this:
www.example.com/blogg/
I noticed right away that the blog was not https. So I went to wordpress admin and changed the URL in general settings from "http" to "https". This seems to have made all links in wordpress, as well as the admin page, use https.
Unfortunately it didnt help when going to the blogg in the web browser, it is still http, although https works if I enter it manually in the browser.
Here is the htaccess file in the wordpress directory (example.com/blogg/.htaccess):
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blogg/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blogg/index.php [L]
</IfModule>
# END WordPress
I am new to .htaccess, and would like some help in finding the right code for all my domain to be https, including the blog. Help is appreciated.
To be clear, I want all http requests to automatically go to https instead.
I have tried adding this line in the second .htaccess file: (no luck though).
RewriteCond %{HTTPS} off RewriteRule ^(.*)$
https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
BR
You can try something like this:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blogg/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blogg/index.php [L]
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*) https://%{SERVER_NAME}/$1 [R,L] //SERVER_NAME = your actual domain name for WP
</IfModule>
# END WordPress
You can also look into this code since its an easier version. It will give you idea about WP htaccess if in root folder as well. :)
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L,NE]
# 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 have added my website to Cloudflare for use of flexible SSL. Everything on static content is ok. For example, I can access my files directly with https (Ex: https://www.samanik.com/logo.png).
but I can't access the WordPress site. I have changed both the site_url and home_url in the db. I have added codes to .htaccess, but when I type my website without https it redirects to https (as I want). But, nothing is shown there. I get an error called ERR_TOO_MANY_REDIRECTS I don't know how to fix this problem.
Here is my .htaccess content.
# 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
<IfModule mod_rewrite.c>
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>
Can anyone help me?
You can redirect to HTTPS using action hook as well.
Add the below code in your **functions.php**:
function redirectToHTTPS(){
if($_SERVER['HTTPS']!="on"){
$redirect= "https://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
header("Location:$redirect");
}}
add_action('init','redirectToHTTPS' );
For detailed guide, check here.
in General Settings set your WordPress Address (URL) Site Address (URL) to https://...
update:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# BEGIN WordPress
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
I am trying to redirect my site from non-www to www.Content of my htaccess is:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^quadriacapital.com [NC]
RewriteRule ^(.*)$ http://www.quadriacapital.com/$1 [L,R=301]
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
But am getting error after putting this code into my htaccess "Page is not redirected properly".
Please help.
try to something like this...
RewriteEngine On
RewriteCond %{HTTP_HOST} ^quadriacapital.com$
RewriteRule (.*) http://www.quadriacapital.com/$1 [R=301,L]
We recently moved from a Clover site to a Wordpress site so the structure on our podcasts has changed. We have two podcast feeds, one for audio, and one for video.
The old podcast feeds were pulling in from these urls...
http://nmconline.net/podcast.php?pageID=27
http://nmconline.net/podcast.php?pageID=28
Our new feeds are sitting at...
http://nmc.church/feed/videopodcast
http://nmc.church/feed/audiopodcast
I've tried the redirect a few different ways but still no luck. I've tried using a straight 301 redirect and just recently move to a RewriteRule, but still won't work. Not sure if its important or not, but I am forwarding the old nmconline.net domain to our new nmc.church domain.
Here is my current .htaccess file.
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^podcast\.php?pageID=27 http://nmc.church/feed/videopodcast [R=301,L]
RewriteRule ^podcast\.php?pageID=28 http://nmc.church/feed/audiopodcast [R=301,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Thanks in advance!
You cannot match QUERY_STRING in a RewriteRule. Here is how you can do:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} ^pageID=27$ [NC]
RewriteRule ^podcast\.php$ http://nmc.church/feed/videopodcast? [R=301,L]
RewriteCond %{QUERY_STRING} ^pageID=28$ [NC]
RewriteRule ^podcast\.php$ http://nmc.church/feed/audiopodcast? [R=301,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
? at the end of URL will remove previous query string.
I am hoping that you can help me with the htaccess rewrite rule below.
# BEGIN WordPress
# WPhtc: Begin Custom htaccess
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{SERVER_PORT} !^443$
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
I have recently changed my wordpress site from http to https... The problem is that old url's redirect to the domain name instead of the https version of that page
eg
if I access the following page https://domain.com/test/testing/ it works 100%, now if I change the https part to http then the page redirects to https://domain.com instead of to https://domain.com/test/testing/ how do I fix it so that if you go to the old version page http://domain.com/test/testing/ (the not https version) that it redirects to https://domain.com/test/testing/ instead of just the domain name https://domain.com
You have to find a workaround for %{REQUEST_FILENAME} since this only represents the file that is accessed. But you obviously want to access the SSL vHost.
So you might hardcode the https into your .htaccess.
RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
This might help you alot. (found the code above there)
I've been struggling also with this issue and finally I found a solution for the home redirection and the wordpress in the same htaccess file, and finally it also works for old http links, redirecting to https:
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$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
I tried your solution. It worked well, but if you do that you'll need to manually change all your internal links.
This works better ;)
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.yourdomain.com/$1 [R,L]
I use this .htaccess for wordpress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{ENV:HTTPS} !=on
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R,L]
# BEGIN WordPress
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>