I run WordPress in the root of my site, but dislike the fact that whenever anyone mistypes a url anywhere else in my site, they get sent to the WordPress error page. The fix is fairly simple if WordPress is installed in its own directory…
Edit your .htaccess in the root of your site to look like this:
# BEGIN WordPress
RewriteEngine On
RewriteBase /
RewriteRule ^archives/.*$ /index.php [L]
RewriteRule ^feed.*$ /index.php [L]
RewriteRule ^page/.*$ /index.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^wordpress/.*$ /index.php [L]
# END WordPress
Now, when a user mistypes a url in the non-wordpress portions of your site, they will see a normal apache error. I use the archives/ formatting for my old posts, you may have to customize yours differently. Additionally, you may need to modify the last line if your blog is not installed in wordpress/. The last few lines DO need to remain there, because WP seems to do some fancy re-writing for the more advanced bits of the admin interface, such as adding open-ids to user profiles.
You may need to add other lines depending on what other modules you may have installed that add further items to the root namespace besides the page views.
I also have the lines:
Redirect 301 /login http://thefire.us/wordpress/wp-login.php
Redirect 301 /logout http://thefire.us/wordpress/wp-login.php?action=logout
which allow me to log in and out via http://site/login rather than retyping or bookmarking the admin url.
Comments
Thanks, this was very helpful.
Posted 10 Dec 2009 at 8:33 AM ¶Whoops, I had to change it back.
Posted 10 Dec 2009 at 8:49 AM ¶It broke the ability to page back on search results pages.
Any ideas?
Ah, thanks for this hint.
Posted 18 Feb 2010 at 3:15 AM ¶Another option, place this in the RewriteConds:
RewriteCond %{REQUEST_URI} !\.(gif|png|jpg|js|css)$
It doesn’t catch as much, but for most HTML requests I’d think you’d *want* WP’s nicer 404 page.
Posted 23 Aug 2010 at 8:31 AM ¶I wrote this code specifically because WP’s 404 was stomping all over other projects which provided their own 404 mechanism. But I suppose that some might prefer to only show a normal 404 for media like you specified. It wasn’t what I was going for.
Posted 23 Aug 2010 at 8:22 PM ¶Hi,
This code solved the WP 404 hijacking of my site, but permalinks now seem to be broken (404′d ironically!).
I use the ‘www.site.com/myblog/archives/year/month/date/post-title/’ format. And edited your code to suit:
RewriteEngine On
RewriteBase /
RewriteRule ^archives/.*$ /index.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^myblog/.*$ /index.php [L]
Any help would be appreciated, thanks.
Posted 11 Mar 2011 at 4:25 AM ¶Post a Comment