Forum Moderators: phranque
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]
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.