Reputation: 63
:: 1.) Intro ::
.htacces looks like this:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^((?!index\.php)[^/]+)/?$ index.php?page=$1 [L]
RewriteRule ^((?!index\.php)[^/]+)/([A-Za-z0-9]+)/([0-9]+)/([0-9]+)/?$ index.php?page=$1&keyword=$2&zip=$3&range=$4 [L]
RewriteRule ^((?!index\.php)[^/]+)/([A-Za-z0-9]+)/([0-9]+)/([0-9]+)/([A-Za-z0-9]+)/?$ index.php?page=$1&keyword=$2&zip=$3&range=$4&action=$5 [L]
#ONLY 1 OF THIS RULES WORK -> ASK STACKOVERFLOW!
RewriteRule ^((?!index\.php)[^/]+)/([A-Za-z0-9]+)/([0-9]+)/?$ index.php?page=$1&ctitle=$2&cid=$3 [L]
RewriteRule ^((?!index\.php)[^/]+)/([A-Za-z0-9]+)/([0-9]+)/?$ index.php?page=$1&ptitle=$2&pid=$3 [L]
Please have a look at the last two rules:
RewriteRule ^((?!index\.php)[^/]+)/([A-Za-z0-9]+)/([0-9]+)/?$ index.php?page=$1&ctitle=$2&cid=$3 [L]
RewriteRule ^((?!index\.php)[^/]+)/([A-Za-z0-9]+)/([0-9]+)/?$ index.php?page=$1&ptitle=$2&pid=$3 [L]
These Rules will do the following things:
Rewrite page1 [local or live environment url]/index.php?page=page1&keyword=test&zip=12345&range=50
to this: [local or live environment url]/page1/test/12345/50
OR page2 [local or live url here]/index.php?page=page2&keyword=test&zip=12345&range=50
to this: [local or live url here]/page2/test/12345/50
:: 2.) Problem ::
Both rules don't work together because of the same count of expected url parameters, but the parameter names aren't the same
:: 3.) Possible solution ::
I could use universal parameter names for both pages so both pages simply use the same paremeters but I'm not sure if I once need different parameter names when I develop my project further and further.
:: 4.) Desired solution ::
I want to make the decision in each rewrite rule. An indikator could be the pagename. I tried some solutions but they don't work properly. Where and how would I have to insert the pagename eg 'page1' and 'page2' so I can use both very similar reWriteRules?
EDIT:
NOTE: Panama Jack asked the right question here. The Pagename is not dynamic in this case.
Upvotes: 0
Views: 51
Reputation: 129
This is how it works for me now:
RewriteRule ^page1/([A-Za-z0-9]+)/([0-9]+)/?$ page1&ctitle=$1&cid=$2 [L]
RewriteRule ^page2/([A-Za-z0-9]+)/([0-9]+)/?$ page2&ptitle=$1&pid=$2 [L]
Any suggestions for improvement?
Upvotes: 0
Reputation: 24448
You rules can be as simple as this since the pages aren't dynamic. Probably most simple example.
RewriteRule ^page1/([^/]+)/([A-Za-z0-9]+)/([0-9]+)/?$ index.php?page=$1&ctitle=$2&cid=$3 [L]
RewriteRule ^page2/([^/]+)/([A-Za-z0-9]+)/([0-9]+)/?$ index.php?page=$1&ptitle=$2&pid=$3 [L]
Upvotes: 1