.htaccess

From IThemes Codex
Revision as of 21:51, June 13, 2011 by Akers (Talk | contribs)
Jump to: navigation, search

Contents

Description of .htaccess

The .htaccess file is a plain text file containing rules for rewriting URLs. For example if a user browses to http://yoursite.com/test/ this may be rewritten to internally send the user to http://yoursite.com/index.php?page=test without them seeing this. This is an easy way to have better looking URLs that run one script or piece of software. WordPress uses rewrites to allow for standard or custom permalinks.


Quickly repair damaged/problematic .htaccess file

  1. Rename your .htaccess file to .htaccess.bak as a backup (just in case).
  2. Navigate to your WordPress admin (usually http://yoursite.com/wp-admin/).
  3. Under the Settings menu select Permalinks
  4. Click the Save button. This will generate a new .htaccess file.
  5. Verify that your problem is now fixed.

Example standard .htaccess file

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress


Line by line breakdown

# BEGIN WordPress
  • This is a comment informing WordPress' internals where its rewrites begin.
<IfModule mod_rewrite.c>
  • This informs the web server to only parse the following lines if rewrites are available.
RewriteEngine On
  • Enable rewrites.
RewriteBase /
  • Base URL for rewriting. If WordPress is in a subdirectory named 'subdirectory' then this should be: RewriteBase /subdirectory/
RewriteCond %{REQUEST_FILENAME} !-f
  • This is used for permalink parsing and may vary.
RewriteCond %{REQUEST_FILENAME} !-d
  • This is used for permalink parsing and may vary.
RewriteRule . /index.php [L]
  • This is the destination that rewritten URLs are directed to. If WordPress is in a subdirectory named 'subdirectory' then this should be: RewriteRule . /subdirectory/index.php [L]
</IfModule>
  • End lines that only parse if rewrites are available.
# END WordPress
  • This is a comment informing WordPress' internals where its rewrites end.
Personal tools
Namespaces
Variants
Actions
iThemes Codex
Codex Navigation
Toolbox