Reputation: 563
I have the following rules in my .htaccess file
RewriteEngine On
#1. home page redirection
RewriteRule ^$ php/home.php [QSA,L]
#2. Detect Non valid files (for menus)
RewriteCond %{REQUEST_FILENAME} !-f
#3. append php/query.php
RewriteRule ^(.*)$ php/$1.php [QSA,L]
UPDATE : The problem was that I did not have .htaccess in wp directory.
This working fine but I have recently installed wordpress in a sub folder of my website called wp. Listing the wordpress posts works fine in my blog.php.
The user access the blog webpage by this url http://mysite/blog
then rule #2
is executed.
The problem is that rule #2 and #3 is also fired when accessing the wordpress articles and admin portal. How do I prevent that from happening in this situation, i need to access the below URLs.
Internal Server Error
http://mysite/wp/wp-admin
Internal Server Error
http://mysite/wp/some-article
Folder structure
|-mysite
|- css
|- .htaccess
|- wordpress
|- wp
|- wp-admin
|- php
|- index.php
|- blog.php
|- js
Any help/advice much appreciated.
Thanks
UPDATE : Everything is working now - This is my .htaccess file
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^$ php/home.php [QSA,L]
#WP articles
RewriteRule ^blog/([A-Za-z0-9-]+)/?$ wp/$1 [QSA,L]
#WP archives
RewriteRule ^blog/([0-9]{4}/[0-9]{2})/?$ wp/$1 [QSA,L]
#WP search
RewriteCond %{QUERY_STRING} ^s=(.*)$
RewriteRule . wp/$/%1? [QSA,L]
#WP categories
RewriteRule ^blog/category/([A-Za-z0-9-]+)/?$ wp/$1 [QSA,L]
#WP tags
RewriteRule ^blog/tag/([A-Za-z0-9-]+)/?$ wp/$1 [QSA,L]
#WP authors
#Insert authors redirect
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ php/$1.php [QSA,L]
</IfModule>
I also experienced a 404 error when accessing my blog page - this was
caused by including the wp-blog-header.php file, the solution was to
insert the following code in my blog.php and remove
include('wp/wp-blog-header.php)
<?php
require('./wp-config.php');
$wp->init();
$wp->parse_request();
$wp->query_posts();
$wp->register_globals();
?>
Upvotes: 1
Views: 1337
Reputation: 7739
First, #2 is not a rule, it is a condition for executing the folowing rule (#3).
To fix your issue, there is multiple solutions, you can add for example a condition to not redirect anything that starts with wp/ :
RewriteEngine On
RewriteRule ^$ php/home.php [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/?wp/
RewriteRule ^(.*)$ php/$1.php [QSA,L]
Upvotes: 1