Mert Mert - 27 days ago 13
PHP Question

RewriteCond %{REQUEST_URI} for all php files

Following code works great. However It takes so much time to do it for hundreds of php files;

RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_URI} !^/abc.php
RewriteCond %{REQUEST_URI} !^/index.php
RewriteCond %{REQUEST_URI} !^/home.php
RewriteCond %{REQUEST_URI} !^/settings.php
RewriteCond %{REQUEST_URI} !^/messages.php
...
...
...
RewriteRule ^/?([a-zA-Z0-9\-=&_@/.]+)/?$ abc.php?u=$1 [QSA,L]


I have to write all php files line by line. Is there any easy way to do this for all php pages?

Answer

Yes, you can use:

RewriteEngine on
RewriteBase /

# The request is not for a valid file/directory
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+?)/?$ abc.php?u=$1 [L,QSA]

If you want to exclude only PHP files, you can use:

RewriteCond %{REQUEST_URI} !\.php$ [NC]
RewriteRule ^(.+?)/?$ abc.php?u=$1 [L,QSA]