Forum Moderators: phranque
================================================
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME}!-f
RewriteCond %{REQUEST_FILENAME}!-d
RewriteCond %{REQUEST_FILENAME}!-l
# this will show listings by /category/
RewriteRule ^([A-Za-z0-9-]+)/?$ browse.php?cat_title=$1 [L]
RewriteRule ^([A-Za-z0-9-]+)?$ browse.php?cat_title=$1 [L]
# this will show listings with pagination: /category_2/
RewriteRule ^([A-Za-z0-9-]+)_([0-9]+)/?$ browse.php?cat_title=$1&pageNum_Recordset_listings=$2 [L]
RewriteRule ^([A-Za-z0-9-]+)_([0-9]+)?$ browse.php?cat_title=$1&pageNum_Recordset_listings=$2 [L]
# this will rewrite the details for the listings /category/listing_title_10.html
RewriteRule ^(.*)/(.*)_(.*).html$ browse_details.php?listing_id=$3
================================================
My only problem is that when I access site root / I do not see the contents of index.php but the contents of browse.php or browse_details.php, this is because it probably thinks that "/" is the beginning of a category like "/category_name/".
How to make / show contents of index.php?
Any help is appreciated.
Thank you.
- Adrian.
[edited by: adrianTNT at 5:41 pm (utc) on Aug. 6, 2007]
I'd suggest removing that question mark (but read on). If you eliminate that question mark, then the first and second rule become equivalent, and the second rule can be deleted. Same thing for the third and fourth rule.
But, also be aware that your initial three RewriteConds will only apply to the first rule that follows them. Matching rules after that first rule will be applied whether the requested URL-path resolves to an existing file, directory, or symbolic link. That's probably not what you want, and that is a contributing cause of this problem.
I'd suggest re-structuring those RewriteConds like this:
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -l
RewriteRule .* - [S=3]
"Exists checks" are horribly inefficient, and I suggest that you make the patterns in the skip rule as specific as possible, so that the checks are not done unless absolutely necessary. However, the pattern must take into account all of the patterns of the following rules, and since the last rule is very ambiguous, you may be running a lot of checks that you don't need to.
Fixing various other ambiguities and inefficiencies, I'd suggest:
Options +FollowSymLinks
RewriteEngine On
#
RewriteCond %{REQUEST_URI} !^([a-z0-9-]+/?¦.+/[^_]+_[^.]+\.html)$ [OR]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -l
RewriteRule .* - [S=3]
#
# this will show listings by /category/
RewriteRule ^([a-z0-9-]+)/?$ browse.php?cat_title=$1 [NC,L]
#
# this will show listings with pagination: /category_2/
RewriteRule ^([a-z0-9-]+)_([0-9]+)/?$ browse.php?cat_title=$1&pageNum_Recordset_listings=$2 [NC,L]
#
# this will rewrite the details for the listings /category/listing_title_10.html
RewriteRule ^(.+)/([^_]+)_([^.]+)\.html$ browse_details.php?listing_id=$3
Replace all broken pipe "¦" characters above with solid pipes before use; Posting on this forum modifies the pipe characters.
Jim
[edit] Correction as noted in following post [/edit]
[edited by: jdMorgan at 8:12 pm (utc) on Aug. 7, 2007]
Thanks again.
- Adrian.
[edited by: adrianTNT at 3:34 pm (utc) on Aug. 7, 2007]