mod_rewrite help please!

XML, Perl, Python, and other languages can be discussed here, even if it isn't PHP (We might forgive you).

Moderator: General Moderators

Post Reply
taxidave
Forum Newbie
Posts: 1
Joined: Sat Jun 06, 2009 9:38 am

mod_rewrite help please!

Post by taxidave »

Hi,
I have started using Mod Rewrite and have a problem with displaying sub-directories re-writes.

I'm trying to rewrite the following structure
/menu/submenu/content/
I'm using RewriteRule ^/([^/]+)/?([^/]*)/?([^/]*)/?$ /content.aspx?pname=$1&pname2=$2&content=$3 [L]

This does not work and it seems to conflict with an existing rule as follows:
RewriteRule ^adverts/([^/]+)/?([^/]*)/?([^/]*)/?([^/]*)/?$ /detail.aspx?mak_id=$2&mod_id=$3&adv=$4 [L]

This is the code used in the .htaccess file:
######################################

RewriteEngine On
RewriteBase /web/content/
RewriteBase /

############ CMS ############
RewriteRule ^/([^/]*)/?$ /menu.aspx?pname=$1 [L]
RewriteRule ^/([^/]+)/?([^/]*)/?$ /submenu.aspx?pname=$1&pname2=$2 [L]
RewriteRule ^/([^/]+)/?([^/]*)/?([^/]*)/?$ /content.aspx?pname=$1&pname2=$2&content=$3 [L]
#################################

############ Adverts ############
RewriteRule ^taxis-for-sale/pg/([^/]+)/?$ /adverts.aspx?pg=$1 [L]
RewriteRule ^taxis-for-sale/([^/]+)/?([^/]*)/?([^/]*)/?([^/]*)/?$ /detail.aspx?mak_id=$2&mod_id=$3&adv=$4 [L]
RewriteRule ^taxis-for-sale/ /adverts.aspx [L]
#################################

Can you please advise how I can implement the structure susccessfully without having to use the structure with the rule:
RewriteRule ^content/([^/]+)/?([^/]*)/?([^/]*)/?$ /content.aspx?pname=$1&pname2=$2&content=$3 [L]

This rule works but I don't want to use the content directory in front. The rule I would like to use is:

RewriteRule ^/([^/]*)/?$ /menu.aspx?pname=$1 [L]
RewriteRule ^/([^/]+)/?([^/]*)/?$ /submenu.aspx?pname=$1&pname2=$2 [L]
RewriteRule ^/([^/]+)/?([^/]*)/?([^/]*)/?$ /content.aspx?pname=$1&pname2=$2&content=$3 [L]
User avatar
mikemike
Forum Contributor
Posts: 355
Joined: Sun May 24, 2009 5:37 pm
Location: Chester, UK

Re: mod_rewrite help please!

Post by mikemike »

Try changing your ([^/]+) to just (.*). That's what I use and it's always worked fine.
Post Reply