Forum Moderators: phranque
I have made progress, but I ran into a problem when I set up 301 redirects from any URL with /blog/ in it.
How can I redirect all permalinks with /blog/ in them to the root, but leave the requests for things that are actual files alone? (Anything with the extension of php, png, gif, jpg or css must be ignored). When I set it up, I broke my image/css folder structure and my site appeared blank.
Any help is appreciated.
Please post your best-effort code for discussion [webmasterworld.com].
Also, be aware that it is the client (e.g. browser) that resolves relative links based up the lowest-level directory that it "sees" in its address bar. If you are rewriting the URL requested by the client and your pages use page-relative links for included objects (CSS, images, external JS, etc.), then you will likely encounter the common problem of broken object links.
The easiest solution is to use server-relative ( e.g. <img src="/images/logo.gif"> ) or canonical ( e.g. <img src="http://example.com/images/logo.gif"> ) links for included objects.
A rewriting solution is also possible, but incurs a duplicate-content problem (it "creates" more than one URL for a single resource).
Jim
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME}!-f
RewriteCond %{REQUEST_FILENAME}!-d
RewriteRule ^blog/?(.*) /$1 [R=301,L]
</IfModule>
Now my problem is that it rewrites the blog admin page as well. How can I exclude rewrites with a specific phrase? ie. /wp-admin/
Does the path to /wp-admin/ also start with "/blog"? If so, add another RewriteCond at the top of the others:
RewriteCond %{REQUEST_URI} !^/blog/wp-admin/
RewriteCond $1 !^wp-admin/
You can also dump the <IfModule> container if you would prefer to get an error message instead of a silent failure in the case that mod_rewrite is not installed and loaded on your server.
Jim