Having trouble with a rewrite rule

Posted on 2011-09-08
Last Modified: 2012-05-12
I'm using a rewrite rule to parse URLS and break them down into parameters:-

]RewriteRule ^([A-Za-z0-9\-]+)/([A-Za-z0-9\-]+)/([A-Za-z0-9\-]+)/([A-Za-z0-9\-]+)/([A-Za-z0-9\-]+)$ /indexa.php?a=$1&b=$2&c=$3&d=$4&e=$5 [L] 
RewriteRule ^([A-Za-z0-9\-]+)/([A-Za-z0-9\-]+)/([A-Za-z0-9\-]+)/([A-Za-z0-9\-]+)$ /indexa.php?a=$1&b=$2&c=$3&d=$4 [L]
RewriteRule ^([A-Za-z0-9\-]+)/([A-Za-z0-9\-]+)/([A-Za-z0-9\-]+)$ /indexa.php?a=$1&b=$2&c=$3 [L]
RewriteRule ^([A-Za-z0-9\-]+)/([A-Za-z0-9\-]+)$ /indexa.php?a=$1&b=$2 [L]
RewriteRule ^([A-Za-z0-9\-]+)$ /indexa.php?a=$1 [L]
RewriteRule ^()$ /indexa.php [L]

Open in new window

This has been working fine until I try and install  a CMS add in. I put a rule in to exclude the CMS system:-

RewriteRule ^/cms/(.*)$ /cms/$1 [L]

Open in new window

In most cases such as:-


The rule behaves fine. However fails to rewrite URLs to folders without the trailing / eg:-


I'm not A1 on regex. Am I missing something obvious here?

I can't easily change the way that these latter URLS are coded in the CMS system as it supplied to me to use.
Question by:cescentman
  • 3
  • 3

Assisted Solution

cescentman earned 0 total points
ID: 36509234
Any takers?
LVL 26

Expert Comment

ID: 36538441
Hi, loose your CMS rule and stick the following rules in front of your original block, to bypass the logic if the URL starts with a /cms/:

# Skip the next block if the URL starts with /cms
RewriteRule /cms/?$.  -   [S=7,NC]
RewriteRule /cms/?.*  -   [S=6,NC]

Adjust the skip rule account [s=#] to suit.
LVL 26

Assisted Solution

arober11 earned 100 total points
ID: 36538455
Sorry typo, must remember to turn of iOS's predictive text before typing code:

# Skip the next block if the URL starts with /cms
RewriteRule /cms/?$  -   [S=7,NC]
RewriteRule /cms/.*    -   [S=6,NC]
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.


Accepted Solution

cescentman earned 0 total points
ID: 36542961
Thanks for the help. This didn't work. Finally however I lighted on:-

RewriteRule ^cms - [L]

Which solves the problem.

Author Closing Comment

ID: 36565425
Thanks for helping
LVL 26

Expert Comment

ID: 36545633
One thing i did't spot earlier I'm guessing your rules are a .htaccess file rather than the more efficient httpd.conf, as no leading / in you chosen solution.

If you are using a .htaccess file removing the leading / should get the logic to work, while permitting you to have some cms rules further down in the file.

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
remove Handler and Add Handler for one file 3 39
IPv6 Networking 6 95
htaccess restrict subdomain 4 84
Apache/PHP: Cannot make phpinfo() and phpmyadmin work 4 34
As Wikipedia explains 'robots.txt' as -- the robot exclusion standard, also known as the Robots Exclusion Protocol or robots.txt protocol, is a convention to prevent cooperating web spiders and other web robots from accessing all or part of a websit…
Hi, in this article I'm going to teach you how to run your own site, and how to let people in (without IP). I'll talk about and explain each step... :) By the way, everything in this Tutorial is completely free and legal. This article is for …
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now