Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

How are rewrite rules applied in WordPress? I don't see any rules in the .htaccess file...

For example, if I set the address URL to www.example.com, then calls to example.com will 301 redirect to www.example.com, but I don't see any rule for that in the .htaccess:

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

# END WordPress 
share|improve this question
    
All the rewrite rules are stored in the database. –  v0idless Nov 6 '11 at 16:08
    
I'm asking about how the rules are applied, not where they're stored. –  Yarin Nov 6 '11 at 16:12
add comment

2 Answers

index.php acts as a router. All requests are sent through index.php which looks up the rules in the database and directs you to the correct location. This should give you an idea of how a PHP router works. The .htaccess just removes index.php from the URL. More rules can be created using the WP_Rewrite class.

share|improve this answer
add comment

When Your index.php is loaded wordpress askes for your "website url"
That adress is preDefined in your database.

As for posts and pages in the case you are using pretty links meanina
a custom permalink structure & in the case you have changed the url after initial draft is saved wordpress uses a 301 permenent redirect.

If you are asking from an seo point of view you should know the your Base URL is the one you have set in your admin meaning:
settings >> general >> WordPress address (URL)

So... (from an seo point of view) you should take a moment to set
up the preffered address in google webmaster tool in order to keep all your link juice directed to the right place since technicily speaking
somewebsite.com & www.somewebsite.com are 2 different addresses.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.