Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

This is the .htaccess code in WordPress. Can someone explain how it works?

This is the .htaccess code for permalinks in WordPress. I don't understand how this works. Can someone explain?

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

I googled and found out that -f and -d part means to give real directories and files higher priority.

But then what are ^index\.php$ - [L] and RewriteRule . /index.php [L] ?

How does WordPress process categories, tags, pages, and etc. with just this?

Does it happen internally? If so, I'm interested in learning how to do it in PHP.

Thanks

like image 246
webnat0 Avatar asked Feb 21 '11 03:02

webnat0


People also ask

What does .htaccess do WordPress?

In WordPress, . htaccess is a special configuration file that can control how your server runs your website. As one of the most powerful configuration files, . htaccess can control 301 redirects, SSL connections, password protection, the default language, and more on your WordPress site.

How does a .htaccess file work?

. htaccess files (or "distributed configuration files") provide a way to make configuration changes on a per-directory basis. A file, containing one or more configuration directives, is placed in a particular document directory, and the directives apply to that directory, and all subdirectories thereof.

How do I set up .htaccess in WordPress?

Log into your web hosting account, navigate to the 'public_html' folder and look for the . htaccess file in WordPress installation. Right-click and click on the 'View/Edit' option to open it in your preferred text editor. Make the required changes and save the file.

Is .htaccess necessary for WordPress?

WordPress should automatically create the . htaccess file if your web server supports it. However, things can always go wrong, which might mean that you need to manually create the WordPress . htaccess file instead.


1 Answers

^index\.php$ - [L] prevents requests for index.php from being rewritten, to avoid an unnecessary file system check. If the request is for index.php the directive does nothing - and stops processing rules [L].

This block is all one rule, and it says that if it is not a real file and not a real directory, reroute the request to index.php.

RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] 

index.php itself interprets the URL that was requested by the client (PHP can see the requested URL using $_SERVER['REQUEST_URI']) and it calls the correct code for rendering the page the user requested.

like image 163
Kevin Stricker Avatar answered Sep 22 '22 19:09

Kevin Stricker