I am trying to setup my htaccess file such that all 404 pages are permanently redirected to the home/index page using 301. After I configure the htaccess file I try to test that it is working correctly by typing in a bogus URL such as site.com/asdf to see if the 404 will redirect. It does not, it just displays the page not found message from WordPress and fails to redirect to the homepage.  The code I am using (below) seemed to be working over on Stack Overflow (). I have even tried creating a PHP script to use with htaccess to redirect 404's, but still the same result, no redirection.  # BEGIN WordPress &lt;IfModule mod_rewrite.c&gt; RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] &lt;/IfModule&gt;  RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteRule . / [L,R=301] # END WordPress
124126
Hi i have recently moved my forum from Mybb to Vanilla, so the index pages such as showthread.php now do not exist. This is a big problem for SEO, what do I do to redirect this to the home page?
91310
I'm currently working on a plugin, and I essentially want to check if a certain page has been created.  Essentially, I want to do something like this:      if (file_exists($file)) {     $exists = true; } else {     $exists = false; }   But I just want to do it so that it checks, instead, for a post_name value. (If I was further able to ensure that the post was a page and not just a post with that title, that would be great too.)  How do I do this?  I had been getting the script to grab the headers from the url of the post and if it returned a 404, to return $exists = false, but I've pinpointed a memory leak problem with that and I don't think it's very efficient.
91905
I made a site some time ago and after some days some posts were indexed by search engines. Today I changed the permalink structure from /%postname%/ to  /%category%/%postname%/.  After that, when people come to my site from search engines a 404 page not found error appears. I want to change all old URLs to the new category base URL without any 404 error.  How can I do it? By the way, I use Yoast plugin.
88295
I am trying to make my url from this:  example.com/view.php?id=15   To this:  example.com/watch/15   My code in .htaccess is as follows:  Options -Indexes Options +FollowSymlinks RewriteEngine On RewriteRule ^watch/([^/]+) view.php?id=$1 [NC]   Now if I go to example.com/watch/15 it loads the content but without any JS, CSS because in this case it looks for CSS and JS under the /watch folder which doesn't exist.  How do I make this option work properly? I don't want to create watch folder and copy-paste CSS and JS so it will embed properly.
32737
Question, is it ok for one of the pages levels to 404? (SEO-wise)  Let's say I have a sitemap like this:  example.com --/services   --/foo   --/bar --/sectors   --/my-sector   --/another-sector   --/the-sector   --/stuff --/about-example --/contact --/etc --/etc   This makes a lot of structural sense. However, from a design point of view, I think having a page to show all the sectors (example.com/sectors) is pointless since all of the sector pages can be accessed from the home page, main navigation, and in each sector page.  Would there be any SEO consequences if the /sectors page were to 404?  Note: in the sitemap 'example.com/sectors' would not be included.
100409
I am asking this because whenever I hover over a link to a home page (e.g. http://www.example.com), I notice that a trailing slash is always added (as observed on the status bar of the browser) whether the home page link contains a href attribute that ends with a slash or not. But whenever I am on the home page, the URL on display will not have a trailing slash.  I tried entering a slash to the URL in the URL bar. And with Firebug enabled, I notice that the site always return a 200 OK status. An article  discussing this states that having a slash at the end will avoid a 301 redirection. But I am not seeing any redirection, even on  page.  Could this be a browser feature that is appending the slash?
81195
hey all! i have an odd problem with URL routing. when i request a URL that doesn't exist, e.g. , wordpress correctly returns a 404. however, if that URL is a prefix of a post or page name, it instead returns a 301 redirect to the post or page.  for example, if i have a post on 10/1/2010 named Food Post, it will return a 301 with Location:  (my permalink structure). likewise, if i have a page named Food Page, it will return a 301 with Location: .  you can see this in action on my live site,  . e.g.  redirects to  .  turning off permalinks (ie switching to "default") fixes it, for both posts and pages, but naturally i don't really want to do that.  i see this on three different installations, all wordpress 3.0.1 and apache 2.2, two ubuntu lucid/mysql 5.1 and one freebsd 7.3/mysql 5.0. i've deactivated all plugins and removed everything from my .htaccess except the lines for wordpress below, verbatim, but no luck.  RewriteEngine On RewriteBase / RewriteRule ^wordpress/index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /wordpress/index.php [L]   thanks in advance...
118923
WordPress keeps writing rewrite rules into .htaccess again and again till it causes an error and causes server to return 500 Internal server error...  i.e. My .htaccess is a series of  # BEGIN WordPress &lt;IfModule mod_rewrite.c&gt; RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] &lt;/IfModule&gt;  # END WordPress # BEGIN WordPress &lt;IfModule mod_rewrite.c&gt; RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] &lt;/IfModule&gt;  # END WordPress   repeated over and over and over again.    By itself, that's not a massive problem (except that my .htaccess will grow to several MBs, slowing down the site significantly). But occasionally, there would appear some garbage in the .htaccess which takes the site down (500 Internal Server Error)
107655
Is there a way to show a 404 page if the current logged in user does not have the right clearance to view the page? I am looking for a PHP method, something like  if( !current_user_can('administrator') ) { show_404(); exit(); }   I have thought about using a redirect, but I would like to keep the url the same.
110134
I have a wordpress site that has had a large number of blog posts removed. How can i ask google to remove all these 404 page not founds, but leave the active blog posts. I see the removal tool in google webmasters but it doesnt say if it will just remove the 404s. I understand 404s naturally are removed from the index, but i want to expedite this.
43257
You can make a catch-all rewrite rule for apache that acts somewhat like an alias, but can be implemented in a .htaccess file while an alias can't.  As an example, assuming your document root is a hierarchy like this:  /.htaccess /test/ /test/.htaccess /test/file   You can "Alias" all requests to the test folder by making the root .htaccess contain:  RewriteEngine On RewriteRule ^(.*)$ /test/$1 [L]   And the second .htaccess contain:  RewriteEngine On   This works great, and usually is all you need. It just has one problem - it creates multiple valid urls. Now you can access the file with both /file and /test/file.  Ordinarily this isn't a problem, but if you add a file called /test/test you'll see the problem, as the fake alias stops working entirely. If the subfolder has a complex .htaccess of its own it can cause major headaches.  Is there any way to fake an alias from a .htaccess without the original urls still working? (Any RewriteCond for the subfolder that would check if we've already been rewritten or not?)
109767
I have created custom rewrite rules. These rules now go to 404 page as expected. I can use action hook template_redirect to change the template matching query_var.  But I don't want to create separate template files as the page structure depend on the current theme in use. Rather I just want to change the content and title. I have tried change the content using the_content filter, but it seems the filter doesn't even get called for 404 page.  I also tried loading index.php template and then using the_content filter, but it also doesn't work.  Is there any way to achieve this?
59079
Here is what I have got:   CentOS 5.4 (32-bit)    installed Apache httpd (Server version: Apache/2.2.11 (Unix)) mod_rewrite already presents   Question: how to redirect simple  to  not using VirtualHost defines?  PS: tried to find in later answers on SF, but doesn't find nice solution.  Thanks.
49165
I want to serve a specific Wordpress page for multiple urls. Basically I want to point all the urls in a specific format to a known page:  /some-prefix-* =&gt; /target-page   And accessing /some-prefix-and-here-something it should load /target-page.  How to do this?  Note I do not want to redirect the user but to be able to serve an existing page to multiple urls.  The .htaccess looks like this:  # BEGIN s2Member GZIP exclusions RewriteEngine On RewriteRule ^prefix-*$ some/path/to/directory-$1 [NC,L] &lt;IfModule rewrite_module&gt;     RewriteEngine On     RewriteBase /     RewriteCond %{QUERY_STRING} (^|\?|&amp;)s2member_file_download\=.+ [OR]     RewriteCond %{QUERY_STRING} (^|\?|&amp;)no-gzip\=1     RewriteRule .* - [E=no-gzip:1] &lt;/IfModule&gt; # END s2Member GZIP exclusions  # BEGIN WordPress &lt;IfModule mod_rewrite.c&gt; RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] &lt;/IfModule&gt;  # END WordPress  DirectoryIndex index.php index.html   I thought by adding RewriteEngine On RewriteRule ^prefix-*$ some/path/to/directory-$1 [NC,L] will serve /prefix-* from some/path/to/directory-$1. For example: when accessing example.com/prefix-foo should be the same with example.com/some/path/to/directory-foo (which resolves to example.com/some/path/to/directory-foo/index.html).  Also, if there is already a Wordpress page with the name prefix-bar, /prefix-bar should not load example.com/some/path/to/directory-bar/index.html.
84649
Openshift application url: example.rhcloud.com  Custom domain: example.com  I came across this  and added the redirection rule. However, I can not access example.rhcloud.com now. My custom domain is www.example.com.  To avoid duplicate content problems, I tried this redirection.   Here is my .htaccess file:  RewriteEngine on   # Uncomment the following lines to force HTTPS #RewriteCond %{HTTP:X-Forwarded-Proto} !https  #RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [R,L]   # WordPress Defaults RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L]  # Redirect Https traffic to Http RewriteEngine on  RewriteCond %{SERVER_PORT} ^443$ [OR] RewriteCond %{HTTPS} on RewriteRule  ^(.*)$ http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]   # Redirect non-www to www RewriteEngine on  RewriteCond %{HTTP_HOST} !^www\. [NC] RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]    # Redirect openshift rhcloud domain to custom domain RewriteEngine on  RewriteCond %{HTTP_HOST} ^example.rhcloud.com$ RewriteRule (.*)$ http://www.example.com/$1 [R=301,L]   Why is example.com not redirecting to ww.example.com? How do I fix this?  Also, I see that since I have https to http redirection and non www to www redirection, my blog has been loading slow. How can I reduce it to lesser number of rules?  Edit:  In chrome:   In Firefox:     The page isn't redirecting properly, Firefox has detected that the server is redirecting the request for this address in a way that will never complete.     This problem can sometimes be caused by disabling or refusing to accept cookies.
50408
Do you know if I should use &lt;link rel="canonical" tag, or 301 redirect from:  http://example.com to http://www.example.com  ...to avoid a duplicate content penalty in case other pages link to the domain without the www subdomain? Or is Google smart enough now to identify which is the canonical one?
124288
I need a single Wordpress installation to be available from both the main domain (www.example.com) via HTTP and a subdomain (secure.example.com) via HTTPS.  Of course i can just map the subdomain to the Wordpress folder in Nginx config. But will Wordpress be aware that it is called via HTTPS and change all links on the pages to HTTPS ?  Also, how i can i force certain pages to be automatically redirected to their HTTPS equivalent permalink (and then back again to HTTP) ?