SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot
    Join Date
    Oct 2007
    Posts
    100
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    (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
    Make the world better

  2. #2
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,031
    Mentioned
    152 Post(s)
    Tagged
    2 Thread(s)
    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:

    Code:
    RewriteCond %{REQUEST_URI} !file(1|2|3)\.php
    Rémon - Hosting Advisor

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  3. #3
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,644
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    Rémon,

    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!
    Code:
    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.

    basketman,

    As above AND
    Code:
    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]
    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •