1

I've had a look at a few mod_rewrite questions here but nothing they have suggested has worked to date.

I have the below rules:

Options +FollowSymlinks RewriteEngine On RewriteBase / RewriteCond %{HTTPS} off RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [L,R=301] RewriteCond %{HTTP_HOST} !^www\. RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [L,R=301] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^([^-]*)/$ ?action=$1 [L] ## General Pages RewriteRule ^privacy-policy/$ ?action=privacy-policy [L] RewriteRule ^terms-conditions/$ ?action=terms-conditions [L] RewriteRule ^about/$ ?action=about [L] RewriteRule ^contact-us/$ ?action=contact-us [L] RewriteRule ^sitemap.xml$ ?action=sitemap [L] ## Blog Pages RewriteRule ^blog/$ ?action=blog [L] RewriteRule ^blog/([a-zA-Z0-9-]+)/$ ?action=blog&category=$1 [L] RewriteRule ^blog/([a-zA-Z0-9-]+)/([0-9]+)-([a-zA-Z0-9-]+)/$ ?action=blog&category=$1&id=$2&title=$3 [L] 

The first blog rule works fine and the third blog rule works fine.

The second blog rule isn't working correctly, lets say I have the below URL:

/blog/general/ 

The second blog rule is returning blog/general as the value for categorywhich is incorrect, it should only be returning general as the value for category.

This issue only occurs on my production environment, it doesn't happen on my local dev environment.

I'm really stumped on this one, any suggestions greatly appreciated.

3
  • Can't reproduce it. Do you have other rules as well? Commented Sep 6, 2016 at 21:04
  • @anubhava, no other rules relating to blogs, there are about another 10/15 rules for other areas of the website. The issue doesn't occur on my local dev environment, only on my production environment, very odd. Commented Sep 6, 2016 at 21:46
  • @anubhava blog isn't a directory no, it's a virtual path, there is only on htaccess file on the server. Commented Sep 6, 2016 at 21:51

1 Answer 1

1

Try reordering your rules and merge SSL with www rule to avoid multiple redirects (bad for SEO and client experience):

Options +FollowSymlinks RewriteEngine On RewriteBase / RewriteCond %{HTTP_HOST} !^www\. [NC,OR] RewriteCond %{HTTPS} off RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC] RewriteRule ^ https://www.%1%{REQUEST_URI} [R=301,L,NE] ## General Pages RewriteRule ^privacy-policy/$ ?action=privacy-policy [L] RewriteRule ^terms-conditions/$ ?action=terms-conditions [L] RewriteRule ^about/$ ?action=about [L] RewriteRule ^contact-us/$ ?action=contact-us [L] RewriteRule ^sitemap.xml$ ?action=sitemap [L] ## Blog Pages RewriteRule ^blog/$ ?action=blog [L,QSA] RewriteRule ^blog/([a-zA-Z0-9-]+)/$ ?action=blog&category=$1 [L,QSA] RewriteRule ^blog/([a-zA-Z0-9-]+)/([0-9]+)-([a-zA-Z0-9-]+)/$ ?action=blog&category=$1&id=$2&title=$3 [L,QSA] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^([^-]*)/$ ?action=$1 [L,QSA] 
Sign up to request clarification or add additional context in comments.

2 Comments

Working perfectly now, I suppose it was the general catch all rewrite for the action parameter causing the issue.
That generic rules should come at the end.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.