Wordpress .htaccess rewrite rule not working
I have my wordpress in a sub-folder on my domain with a .htacess
file on the root which does all the redirecting.
i want to do a redirect, the site IP to WWW. which works for the main site on the root but not for the sub-folder which is Wordpress.
iv got a feeling wordpress is overwriting this some where?
this is what iv used in root .htaccess
RewriteCond %{HTTP_HOST} ^IP.IP.IP.IP [NC]
RewriteRule ^(.*)$ http://www.NAME.com/$1开发者_开发百科 [R=301,L]
but this does not work for the wordpress sub-folder
iv even tried to copy this into the .htaccess
file in the WP root folder but still not work
It is because in your Wordpress wp-admin panel there is a setting:
Settings -> General -> WordPress address (URL)
and
Settings -> General -> Blog address (URL)
Make sure to update them to http://www.domain.com/subfolder
then it will start working.
UPDATE (Based on your comments)
Use following .htaccess inside WP install folder '/blog'
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteRule ^/?$ /blog/index.php [L]
RewriteCond %{HTTP_HOST} ^IP\.IP\.IP\.IP$
RewriteRule . http://www.NAME.com%{REQUEST_URI} [R=301,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>
# END WordPress
.htsccess file overrides the .htaccess files in the parent directories. In your case, the WordPress blog directory has a .htaccess file which is overriding the .htaccess file in the root. This is why you see it working for the root, but not for the subdfolder, say, /blog.
You should not be replacing the .htaccess created by WordPress. Add
the rewrite rules in the existing .htacess file in the subdirectory and make sure this is the first rule in the file(i.e inside <if ...>
block). If you are using WP Super Cache or similar plugin, make sure you create a new if block above the rules created by the plugins and leave the WordPress created <if ...>
block intact.
<edit>
In your root folder,
RewriteCond %{HTTP_HOST} ^IP\.IP\.IP\.IP [NC]
RewriteRule ^(.*)$ http://www.NAME.com/$1 [R=301,L]
In your WP directory(WPDIR) .htaccess file before any other rule,
RewriteCond %{HTTP_HOST} ^IP\.IP\.IP\.IP [NC]
RewriteRule ^(.*)$ http://www.NAME.com/WPDIR/$1 [R=301,L]
Of course, put it inside the <if ...>
block and turn the RewriteEngine on.
精彩评论