Forum Moderators: phranque
category/page.php
will be redirected to
index.php?cat=category&page=page.php&force=0&idx=1
I use the following rule for this:
RewriteRule ^([^/]+)/([^.]+).php$ /index.php?cat=$1&page=$2&force=0&idx=1 [L]
This works just fine. However, now i need to be able to add the following rules:
category/page -> index.php?cat=category&page=page.php&force=0&idx=1
category/page/ -> index.php?cat=category&page=page.php&force=0&idx=1
category/ -> index.php?cat=category&page=&force=0&idx=1
category -> index.php?cat=category&page=&force=0&idx=1
Offline (in a text editor), i'm able to simulate this behaviour using the following regular expression:
RewriteRule ^([^/]+)(/([^/^.]+)(/){0,1}){0,1}(/){0,1}$ /index.php?cat=$1&page=$2&force=0&idx=1 [L]
However, if i try to use this rule on my server, I get a 500 Internal Server Error...
I've tried different other configurations, but none worked (offline) like to one listed above...
Do i something wrong? And could anyone please point me in the correct direction? :)
Thanks!
Evarest
First off, "[^/^.]" looks funny, and I suspect you may want "[^/.]". Then we have multiple instances of "{0,1}" which can be more efficiently replaced with "?".
A simpler approach might be to add two rules:
RewriteRule ^([^/]+)/([^/.]+)/?$ /index.php?cat=$1&page=$2&force=0&idx=1 [L]
RewriteRule ^([^/.]+)/?$ /index.php?cat=$1&page=&force=0&idx=1 [L]
Jim
That seems to me a logical explanation :)
I'm not at home now, but i will check asap your rules:
RewriteRule ^([^/]+)/([^/.]+)/?$ /index.php?cat=$1&page=$2&force=0&idx=1 [L]
RewriteRule ^([^/.]+)/?$ /index.php?cat=$1&page=&force=0&idx=1 [L]
The idea is that when a user surfs to
[mydomain.com...]
the request is handled by index.php?cat=category&page=page&force=0&idx=1
Also when the user surfs to
[mydomain.com...]
this should happen.
Additionally, the user should get an overview of the pages in each category if he goes to
[mydomain.com...]
This can be done in my index.php if the user goes to
index.php?cat=category&page=&force=0&idx=1
Therefore, the htaccess should also contain a rule for this.
Lastly, the user can go to
[mydomain.com...]
This means that the category = category, page = page and additional parameters are force=forceid and index=1
So index.php should handle this as well:
index.php?cat=category&page=&force=forceid&idx=2
I tried to get this all done in several rules, but that didn't work. So i tried it in 1 rule which i created using a texteditor (that could handle regular expressions). That's how i came up to that complicated rule...
Thanks!