.htaccess文件详解

2025-11-21 05:18:59

1、一、第一步操作

# 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

这是我们开启了固定链接功能之后,wordpress给我们加上的htaccess文件

冷博客来解释一下各行含义

2、二、第二步注意

<IfModule mod_rewrite.c>

#如果mode_rewrite.c模块存在 则执行以下指令

RewriteEngine On

#开启rewriteEngine

RewriteBase /

#重写范围,这里/为本地顶级目录

RewriteRule ^index\.php$ – [L]

#重写规则

^index\.php$是匹配正则表达式,只匹配了index.php

后面的短线 如果我没记错的话 就是指null

后面的L是结束符号,同等级的还有

[L](last):终止一系列的RewriteCond和RewriteRule  

[R](redirect):触发一个显示的跳转,也可以指定跳转类型,如[R=301]  

[F](forbidden):禁止查看特定文件,apache会触发403错误

[NC](no case):表示忽略大小写

3、三、详见文章末尾才出处

其中返回值301也会有其他类型,比如

常用的客户端请求错误返回代码:


  401 Authorization Required
  403 Forbidden
  404 Not Found
  405 Method Not Allowed
  408 Request Timed Out
  411 Content Length Required
  412 Precondition Failed
  413 Request Entity Too Long
  414 Request URI Too Long
  415 Unsupported Media Type

  常见的服务器错误返回代码:


  500 Internal Server Error

RewriteRule . /index.php [L]

#同样是重写规则


声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢