From the Blogabout me

Removing /index.php/ from WordPress URL’s

Occasionally, I have clients ask why their URL’s for WordPress have changed or maybe they moved from one hosting provider to another and they now see /index.php/ in their URL.  This does not only pertain to WordPress though, as it could affect other Content Management Systems (CMS) or even general software.

Recently I was helped setup a person who had moved their WordPress site and a great billing/time tracking online system, that I encourage you to look into, called Pancake from Hostgator to InMotion. But once everything was moved over they noticed this issue in all URL’s and it caused Pancake to really act up without being any issue with Pancake itself, and just made WordPress links look ugly.  So that’s when I realized it was time for me to do a quick walk-through on how removing/index.php/ from WordPress URL’s without a plugin being needed.

So I want you to go into your .htaccess file within the root directory of your website. Open it with your favorite text editor, and make sure this information is there and at the top of the file. Save and put back on the server.

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]
</IfModule>

Note, if you are using Rackspace, you may need to add a little more code:


<IfModule mod_rewrite.c>
Options +FollowSymlinks
# Options +SymLinksIfOwnerMatch
RewriteEngine On

# On some hosts (including Rackspace), you need to remove the "#" that comes before RewriteBase to avoid 404 errors:
# RewriteBase /

# Block access to hidden files and directories.
RewriteCond %{SCRIPT_FILENAME} -d [OR]
RewriteCond %{SCRIPT_FILENAME} -f
RewriteRule "(^|/)\." - [F]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)\.(\d+)\.(js|css|png|jpe?g|gif)$ $1.$3 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [L]
</IfModule>

I realize this is not the most exciting topic, nor the easiest to explain, so if you have any questions please let me know.

Meta Refresh vs 301 redirects (.htacess) ?

Lots of people ask me what the difference between using the Meta Refresh tag verses using the .htaccess 301 redirect function is, so I am here to explain their differences.

So what is the Meta Refresh Tag?

Mostly people want to use this in the <head> section of their webpage to redirect to a different page/site.  For instance, let’s say you had a page that once lived at domain.com/awesome.html but now it is actually located at domain.com/pretty-cool.php.  It may be hard to reach out to all of your visitors, or you have a great search ranking you don’t want to mess up.  You can go into your old page file and add something like this:


<head>
<meta http-equiv="refresh" content="0;'http://domain.com/pretty-cool.php'" />
</head>


This now lets your visitor go straight to the new location without them having to think.  So far so good, right?  Not exactly…

Biggest problem with Meta Refresh is lots of sites use this method to redirect you to rogue or completely different sites.  You probably don’t want your visitors, or Google, thinking you are trying to send your visitors to some completely different place.  You can do this for a short period of time as a bandaid, but I definitely would not recommend it for a long period of time.

So, what do you do instead?



301 Redirect

This is to tell your site, users, and Google you are permanently changing the location of the page.  Most importantly it tells all search engines “hey, the website or page has moved – please don’t hurt me, just look over here now.”

How to do a 301 Redirect is pretty simple.

Open your .htaccess file (or create one) found in your root directory and add a new line:
Redirect 301 http://domain.com/awesome.html http://domain.com/pretty-cool.php
If you want to redirect entire site to a new site, and not just files, you can do this:
Redirect 301 / http://domain2.com/
Save the .htaccess file, make sure it’s on your site, and you are done.

 

Different types of Redirects:

301 = permanent

302 = temporary