Link to home
Start Free TrialLog in
Avatar of cescentman
cescentmanFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Having trouble with a rewrite rule

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:-

/cms/index.php
/cms/
/cms/apps/users/

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

/cms/content

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.
SOLUTION
Avatar of cescentman
cescentman
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of arober11
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.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of cescentman

ASKER

Thanks for helping
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.