SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: index.php as entry point BUT one file

Hybrid View

  1. #1
    SitePoint Zealot
    Join Date
    Jul 2011
    Posts
    199
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    index.php as entry point BUT one file

    Hello,

    Code:
    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    
    # END WordPress
    It works great. Just a problem. There is a link that I don't want to be redirected to index.php: static.html

    Is it possible to tell Apache not to handle static.html?


  2. #2
    Do. Or do not. There is no try silver trophy
    SitePoint Award Recipient ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    8,346
    Mentioned
    87 Post(s)
    Tagged
    2 Thread(s)
    I'm assuming static.html is an existing file. If so, it shouldn't be routed through index.php, because of the line RewriteCond %{REQUEST_FILENAME} !-f which says "Don't execute the following RewriteRule if the requested file actually exists".

    Some other pointers though:

    1) get rid of the <IfModule ...> and </IfModule>; once you've established that mod_rewrite works, you don't need those any more, and you're just putting a strain on the server for nothing
    2) get rid of RewriteBase /. In 99 out of 100 hosts you don't need it, and it can actually do more harm then good.

    (yes, I realize the .htaccess is wordpress generated; I'm not criticising you, I'm criticising the code)
    Rémon - Hosting Advisor

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

  3. #3
    SitePoint Zealot
    Join Date
    Jul 2011
    Posts
    199
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks a lot for the reply, of and you can criticize away, that's how I will learn.

    Yes, static.html exists.

    Ok, I've been through the .htaccess file and found some more rewrite rules (I'm using the html5boilerplate .htaccess, and I've pasted the wordpress code at the top of it).

    Here are all the rules (they were spread around). I haven't yet altered the code so I don't accidentally "hide" an important bit...
    Code:
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    
    <IfModule mod_rewrite.c>
      RewriteEngine On
    </IfModule>
    
    <IfModule mod_rewrite.c>
      RewriteCond %{HTTPS} !=on
      RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
      RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
    </IfModule>
    
    <IfModule mod_rewrite.c>
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/|#(.*))$
      RewriteRule ^(.*)$ /$1/ [R=301,L]
    </IfModule>
    
    <IfModule mod_rewrite.c>
      RewriteRule "(^|/)\." - [F]
    </IfModule>

  4. #4
    Do. Or do not. There is no try silver trophy
    SitePoint Award Recipient ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    8,346
    Mentioned
    87 Post(s)
    Tagged
    2 Thread(s)
    please remove all lines in red, you really don't need them

    Code:
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    
    <IfModule mod_rewrite.c>
      RewriteEngine On
    </IfModule>
    
    <IfModule mod_rewrite.c>
      RewriteCond %{HTTPS} !=on
      RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
      RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
    </IfModule>
    
    <IfModule mod_rewrite.c>
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/|#(.*))$
      RewriteRule ^(.*)$ /$1/ [R=301,L]
    </IfModule>
    
    <IfModule mod_rewrite.c>
      RewriteRule "(^|/)\." - [F]
    </IfModule>
    Rémon - Hosting Advisor

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

  5. #5
    SitePoint Zealot
    Join Date
    Jul 2011
    Posts
    199
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Worked like a charm

    Many thanks!

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
  •