.htaccess文件
Choosing to use WordPress was a more difficult decision that you may think. Sure, WordPress is the most used blogging software on the internet, but I'm a programmer, right? I should want to code everything myself, right? I thought that at first but I decided to try WordPress first and I've been impressed with every part of WordPress so far. One of the interesting parts of WordPress is the URL rewriting and "slug" that gets created for each post. How did they do that?
您可能会认为,选择使用WordPress是一个比较困难的决定。 当然,WordPress是互联网上最常用的博客软件,但是我是程序员,对吗? 我应该自己编写所有代码,对吗? 最初我以为是这样,但我决定先尝试WordPress,到目前为止,WordPress的每个部分都给我留下了深刻的印象。 WordPress有趣的部分之一是为每个帖子创建的URL重写和“ slug”。 他们是怎么做到的?
Well, I know enough about SEF (search engine friendly) links to know that an .htaccess file had to be involved so I downloaded the .htaccess file from my hosting server and saw:
好吧,我对SEF (搜索引擎友好)链接了解得足够多,知道必须包含.htaccess文件,因此我从托管服务器下载了.htaccess文件,并看到:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
That's it? Yep. Basically, the flow goes as follows:
而已? 是的 基本上,流程如下:
- We must first establish that mod_rewrite is available on the server 我们必须首先确定mod_rewrite在服务器上可用
- If so, turn on mod_rewrite 如果是这样,请打开mod_rewrite
- Set the base of all rewriting to the web root folder 将所有重写的基础设置到Web根文件夹
- If the requested filename isn't a file.... 如果请求的文件名不是文件...。
- ....and it isn't a folder... ....这不是文件夹...
Send the person to index.php
将该人发送到index.php
Once inside the index.php file, the index.php file processes the request and presents you with the page based upon the slug in the URL. Very simple .htaccess code runs a reliable WordPress blog.
进入index.php文件后, index.php文件将处理请求,并根据URL中的链接向您显示页面。 非常简单的.htaccess代码可运行可靠的WordPress博客。
.htaccess文件