Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
242 views
in Technique[技术] by (71.8m points)

php - 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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

^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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...