You can easily match any URL ending in ".php" with a regex equal to '^(.*\.php)$'. Also, it appears that you want to match URLs having a specific path "depth" (i.e. number of forward slashes). But your regex uses the dot .*? which matches the forward slash, so this may also be part of (or another) problem. In other words, your '^(.*?)/(.*?)/$' regex matches folders two levels deep, but it also matches folders that are twenty levels deep! Instead of the "match-anything" dot, try using the more specific "match-anything-that-is-not-a-forward-slash" '[^/]*' instead. Try the following:
Code: Select all
RewriteEngine on
RewriteRule ^([^/]*)/([^/]*)/preview$ /news/_index.php?version_url=$1&version=$2&preview=true [L]
RewriteRule ^([^/]*)/([^/]*)/$ /news/_index.php?version_url=$1&version=$2 [L]
RewriteRule ^([^/]*)/preview$ /news/_index.php?version_url=$1&preview=true [L]
RewriteRule ^([^/]*)/$ /news/_index.php?version_url=$1 [L]
RewriteRule ^(.*(?<!_index)\.php)$ /news/_index.php?php_file_URL=$1 [L]
I've added a negative lookbehind to the .php rule to only rewrite .php files that are not _index.php - (otherwise it could loop back on itself). You don't want to take a .php file and rewrite it to be another .php file - infinite loop! (This was likeley the cause of the problem when you took away the ending '/'). And of course, you need to fix the destination for the '\.php$' rule.
Edit: now that I think about it, your '^(.*?)$' rule matches (and is re-writing)
every URL in the universe!. That was resulting in an infinite loop and was most definitely the main problem!