Reputation: 5595
I'm looking to have all WordPress rewrites to work except:
/business
be routed to a business
folder in the root dir which contains static html pages.When I set the index to . /index.html [L]
none of the regular wordpress rewrites work. However if I set DirectoryIndex /index.html
I can't figure out how to get rewrites to work for /business
which contains HTML files that need to be served up on the http://mywebsite.com/business
url. Full rewrite rules:
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# RewriteRule . /index.php [L]
RewriteRule . /index.html [L]
Any help is appreciated and, more than just an answer, an explanation of what each portion of the lines you provide does may help myself and others understand how to take this on on their own next time.
UPDATE: Rules are still not working. /wp-admin has worked all along though.
Upvotes: 1
Views: 1346
Reputation: 4294
Try to stick with default WordPress rewrites and simply add DirectoryIndex to prefer .html files over .php files:
DirectoryIndex index.html index.php
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
So rewrites will only happen when requested files or directories are missing (RewriteConds with !-f and !-d flags). And if there is a static index.html along with index.php in a directory (root directory for example), it will be served first.
http://httpd.apache.org/docs/2.2/mod/mod_dir.html#directoryindex
Upvotes: 1
Reputation: 126
Replace this code with your HTACCESS file in root
# Switch rewrite engine off in case this was installed under HostPay.
RewriteEngine Off
SetEnv DEFAULT_PHP_VERSION 53
DirectoryIndex index.cgi index.php
# 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
And also change the URL's from database...
Upvotes: 0
Reputation: 539
Two issues need to be solved:
To solve the first issue, I would rename index.html to front-page.php and move it inside my current theme folder. Then WordPress would serve it (or rather: use it as a template) whenever someone requests the front page, according to the Template Hierarchy.
There is a cost to this solution compared to actually serving a static file: Whenever someone requests you front page, WordPress will still be loaded. If the goal of serving your front page statically is to save server resources by not loading WordPress or PHP on every page load, you should look into caching plugins.
The second issue should not be an issue at all, because the standard WordPress rewrite rules already allow for static files and directories. The lines
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
mean that the redirect to WordPress won't happen if the URL requested is an actual file (-f) or directory (-d). Therefore you will not need any extra rewrite rules to access the /business directory.
The standard WordPress rewrite rules are explained below:
RewriteEngine On # Turn on the rewrite engine
RewriteBase / # Use the domain root as the base of rewrites
RewriteRule ^index\.php$ - [L] # If someone requests the WordPress entry point, stop here
RewriteCond %{REQUEST_FILENAME} !-f # If the requested URL is not an actual file ...
RewriteCond %{REQUEST_FILENAME} !-d # ... and if the requested URL is not an actual directory ...
RewriteRule . /index.php [L] # ... then rewrite it to the main WordPress entry point
When /index.php is loaded, this file will then in turn load WordPress and everything that comes with it.
Upvotes: 0
Reputation: 143906
Try:
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteRule ^business/ - [L]
RewriteRule ^index\.php$ - [L]
RewriteRule ^$ /index.html [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
Upvotes: 0