Consolidate rewrite rules all pointing at same file?

I’ve got two apps running on the same website. One app is a proprietary framework, and the other is WordPress. Both apps were designed to funnel everything through a file named index.php, which I guess you might consider a “bootstrap”, yes? Well, there can’t be two index.php files, so I renamed one to brain_index.php. Brain (the proprietary framework) only needs to handle a few routes, but there all pointed at the same file, so I just want to know if there is a way to consolidate the rewrite rules, or if there is a better way to write this:


# URLs routed to Brain
RewriteRule ^$ /brain_index.php [L]
RewriteRule ^team$ /brain_index.php [L]
RewriteRule ^rentals.*$ /brain_index.php [L]
RewriteRule ^real_estate.*$ /brain_index.php [L]
RewriteRule ^contact$ /brain_index.php [L]

# If file or directory does not exist
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# Route to Wordpress
RewriteRule .* index.php/$0 [PT,L]

I tried your script and it did not work, added the following and it worked OK:



#Options +FollowSymLinks
RewriteEngine On


Hi John,

Maybe I should have been more clear, and also provided the complete .htaccess. My rewrite rules are working, I just wanted to know if there was a better way to route multiple URIs to the same script. See, everything pointed at brain_index.php is special, and then everything else goes to WordPress. Here’s the full working .htaccess:


# MAKE SURE TO LEAVE DENY LIST AT VERY TOP --
# END DENY LIST (DO NOT REMOVE THIS LINE) --

Options -Indexes

RewriteEngine On
RewriteBase /

# Remove WWW
#RewriteCond %{HTTP_HOST} !^your-domain\\.com$ [NC]
#RewriteCond %{HTTPS} !=on
#RewriteRule ^(.*)$ http://your-domain.com/$1 [L,R=301]

RewriteRule ^(app|tests|vendor) - [F,L]

# URLs routed to Brain
RewriteRule ^$ /brain_index.php [L]
RewriteRule ^index\\.php$ /brain_index.php [L]
RewriteRule ^rentals.*$ /brain_index.php [L]
RewriteRule ^real_estate.*$ /brain_index.php [L]
RewriteRule ^contact$ /brain_index.php [L]
RewriteRule ^notice_to_vacate$ /brain_index.php [L]

# If file or directory does not exist
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# Route to Wordpress
RewriteRule .* wp_index.php/$0 [PT,L]

Perhaps another member has a solution.

My knowledge of .htaccess scripts stretches to searching for a solution, cutting & pasting then testing.

No doubt the full .htaccess will certainly help.

Sure. You could use OR to list all the possible URLs side-by-side.

RewriteRule ^(?:team|rentals.|real_estate.|contact)?$ /brain_index.php [L]

Though, keep in mind that fewer lines doesn’t necessarily mean better code. Pick the version that you find easier to read and easier to understand.

Hi Jeff. Thanks for your reply. This is what I wanted to know, and thank you for your advice, too.