Forum Moderators: phranque

Message Too Old, No Replies

mod rewrite help please!

         

taxidave

3:21 pm on Jun 6, 2009 (gmt 0)

10+ Year Member



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]

g1smd

4:23 pm on Jun 6, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You have "optional" characters in the patterns for your rewrites. This means that multiple different URLs could pull the same content.

Do not make slashes optional. Make it so the rewrite only works if trailing slashes are omitted. Precede the rewrite with a redirect that takes a request with the slash and sends a redirect so that the browser has to make a new request without the slash.

The user can still access the content using either slash or no-slash, but only the no-slash URL can be indexed by search engines.

A lot of rules are also ambiguous, and will match something when it is really a later rule that should be matching. Do not make slashes inside the pattern optional.