Inserting WordPress in a site with .htaccess Rewrite Rule
.htaccess files are extremely useful in many cases for users who either do not have root permissions or for users who simply aren't comfortable in making changes in their web server's configuration file. Trying to debug .htaccess not working isn't always the easiest thing to do, however, hopefully by checking the discuss below mentioned about php, htaccess, web-development, wordpress, .htaccess common problems as well as the troubleshooting tips, you'll have a better grasp on what you may have to modify to get your .htaccess file running smoothly.Problem :I want to insert a WordPress blog in a website which is programmed in PHP and that uses includes() to select what content to show, and that uses .htaccess Rewrite Rule to get friendly URLs.
The problem is that when installing WordPress in a subdirectory the rewriteRule executes and doesn't let the user get to the subdirectory where WordPress is located.
One way to solve this could be trying to program the includes to include all the WordPress content, but I think it would be quite difficult (wouldn't it?). Advantage: CSS style preserved!
The other solution I thought about was disabling the Rewrite Rule for the WordPress subdirectory (is it possible? How can it be done?). Disadvantage: CSS nod preserved, should be reinserted modifying WordPress files.
The third way I see is to install WordPress in a subdirectory, although I don't want to use this due to SEO optimization.
.htaccess file:
# Activar RewriteEngine
RewriteEngine on
# When only 1 var is set in the url
RewriteRule ^([a-zA-Z0-9-]+)/?$ index.php?lang=$1
# When 2 vars are set in the url
RewriteRule ^([a-zA-Z0-9-]+)/([a-zA-Z0-9-]+)?$ index.php?lang=$1&link0=$2
# When 3 vars are set in the url
RewriteRule ^([a-zA-Z0-9-]+)/([a-zA-Z0-9-]+)/([a-zA-Z0-9-]+)/?$ index.php?lang=$1&link0=$2&link1=$3
# When 4 vars are set in the url
RewriteRule ^([a-zA-Z0-9-]+)/([a-zA-Z0-9-]+)/([a-zA-Z0-9-]+)/([a-zA-Z0-9-]+)/?$ index.php?lang=$1&link0=$2&link1=$3&link2=$4
# When 5 vars are set in the url
RewriteRule ^([a-zA-Z0-9-]+)/([a-zA-Z0-9-]+)/([a-zA-Z0-9-]+)/([a-zA-Z0-9-]+)/([a-zA-Z0-9-]+)/?$ index.php?lang=$1&link0=$2&link1=$3&link2=$4&link3=$5
You are going to have massive problems if you try to run WordPress out of a directory that also serves up non-WordPress PHP files. Trust me; I did this for several years. You will have add a rule to .htaccess, above WordPress's own, to intercept every single request that shouldn't go to WordPress. If all of the content is of the form /foo-bar-something.php, that's easy. Otherwise, that's a nightmare. Just put it in a different directory/subdirectory.
Comments
Post a Comment