(Basic) Joining rewrite rule

I have these rewrite rules

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(file1.php)
RewriteCond %{REQUEST_URI} !(file2.php)
RewriteCond %{REQUEST_URI} !(file3.php)

RewriteRule ^/?(af|sq|ar)/([^/]+)/?$ /index.php?z-profile=$2&language=$1 [L,QSA]
#RewriteRule ^/?(af|sq|ar)/([^/]+)/?$ vseo.php?bet_lang=$1&redirected=/index.php?z-profile=$2 [L,QSA]
#RewriteRule ^([^/]+)/?$ index.php?z-profile=$1 [QSA]

i want to joining the rewrite rules in bold above so maybe can make it faster and short, what is looks like, thanks for sharing answer guys

First of all, you should escape the dots in those RewriteCond’s because the value of a RewriteCond is a regular expression. That means that the dot means “any character”; not literally a dot. i.e. use filen\.php to literally match a dot and not just any character.

As for combining, you can use the pipe (|) for that, to mean OR.

Lastly, since you don’t use the value that is found, you don’t need the parentheses around (filen\.php) to make it a backreference.

All together:

RewriteCond %{REQUEST_URI} !file(1|2|3)\\.php



Right! Always point out the failure to properly escape the dot character (and NOT to escape it within a character range definition)!

He DID use the pipe for OR within the remaining RewriteRule (not edited) and it was properly referenced in the redirection as $1.

I guess I would have added that most Apache installations are version 2 by now but a webmaster SHOULD know and use the correct “start anchor”.

Apache 1.x => ^/
Apache 2.x => ^
NOT A WEBMASTER (or a “canned” program developer) => ^/?

Finally, he should USE [ CODE ] … [ /CODE ] so his code is preserved in a reply!

RewriteCond %{REQUEST_URI} !file(1|2|3)\\.php

Yes, that would replace all three. However, I suspect that those are pseudonyms for his true filenames so !(file1|file2|file3)\.php might have been better. I rarely take member-referenced domain or file names literally.


As above AND

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(file1|file2|file3)\\.php)
# Apache 2.x assumed
# NEVER use /?$ as a real webmaster KNOWS not to use trailing slashes like that!
RewriteRule ^(af|sq|ar)/([^/]+)$ index.php?z-profile=$2&language=$1 [L,QSA]