Index.php as entry point BUT one file

Hello,


# 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?

:slight_smile:

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)

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… :wink:


<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>

please remove all lines in red, you really don’t need them


[color="red"]<IfModule mod_rewrite.c>[/color]
RewriteEngine On
[color="red"]RewriteBase /[/color]
RewriteRule ^index\\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
[color="red"]</IfModule>[/color]

[color="red"]<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>[/color]

Worked like a charm :slight_smile:

Many thanks!