I am managing a website tasteporto.com that is simple php/mysql with a blog part in wordpress.
On the main website I have the following apache rewrite rules
RewriteEngine On
RewriteBase /
# no-www to www
RewriteCond %{HTTP_HOST} !^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301]
# http to https
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301]
# if not blog, make URLs pretty
RewriteCond %{REQUEST_URI} !^.*\/blog\/.*$ [NC]
RewriteCond %{REQUEST_URI} ^.*\/index [NC]
RewriteRule ^(.*)index\.php$ /$1 [R=301,L]
# if not blog, make URLs pretty by removing file extension
RewriteCond %{REQUEST_URI} !^.*\/blog\/.*$ [NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^\.]+)$ $1.php [NC,L]
On the wordpress directory I have the standard rules plus one to make sure that it is being applied to the blog path:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^.*\/blog\/.*$ [NC]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_URI} ^.*\/blog\/.*$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
All normal links on the website work fine, as well as the starter page for the blog.
The problem is that Wordpress's permalinks like https://tasteporto.com/blog/ready-for-sao-joao/ do this https://www.tasteporto.com/http:/www.tasteporto.com/
I know this is something stupidly simple, but I've been looking at the same problem for too long and could use some help. Can anybody offer some wisdom please?
Thank you from rewrite hell
May be problem derived from following rules:
Please try change it to:
Thank you for your responses, I really appreciate them.
After some trial and error I figured it out. The problem was the baseline for the rewrite rules in the blog part of things.
To start with, something that helped was increased logging to the access and error log files. So in /etc/apache2/mods-available/rewrite.load I added the second line below:
Then here are the rewrites in the website config file in sites-available:
And here is the .htaccess on the main website:
And finally the .htaccess on the blog directory:
The main problem was this last bit with the RewriteBase having changed to /blog.
I hope this helps others.