SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Aug 2008
    Posts
    62
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Conflicting RewriteRule in .htaccess

    Here is a excerpt from my .htaccess located in the public_html folder:
    Code:
    RewriteEngine On
    
    #rewrite rule for redirection
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.+)$ redirection.php?REQUEST_URI=%{REQUEST_URI} [NC,QSA]
    
    #custom error page
    RewriteRule ^errorpage.htm$ errorpage.php [R=301,NC]
    "Errorpage.htm" does not exist anymore. The rewriterule works if the following code is commented out:
    Code:
    RewriteRule ^(.+)$ redirection.php?REQUEST_URI=%{REQUEST_URI} [NC,QSA]
    What I want is nonexisting files and directories to be redirected to "redirection.php" except if the file is "errorpage.htm"

    What is the best way to do this?

  2. #2
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Try the L flag. It should stop any subsequent rules if the line gives a match:
    Code:
    RewriteEngine On
    #custom error page
    RewriteRule ^errorpage.htm$ errorpage.php [R=301,NC,L]
    
    #rewrite rule for redirection
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.+)$ redirection.php?REQUEST_URI=%{REQUEST_URI} [NC,QSA]
    Alternatively you can simply set errorpage.htm to be parsed as PHP and rename errorpage.php to errorpage.htm.


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
  •