且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

.htaccess 和 seo-friendly urls

更新时间:2023-02-23 10:45:32

您正在寻找的 apache 功能称为 mod_rewrite.您应该可以在此处 google 并找到良好的帮助资源.

The apache feature you are looking for is called mod_rewrite. You should be able to google and find good resources for help here.

基本思想是您将指定一个正则表达式匹配,然后指定一个替换模式.可以设置做301重定向,但默认是不重定向用户,只访问重写后的url.

The basic idea is you'll specify a regular expression matching and then a replacement pattern. You can set it to do a 301 redirect, but the default is to not redirect the user, just access the re-written url.

这是一个例子:

RewriteEngine On
RewriteRule (.*) index.php

RewriteRule 表示将任何匹配的 url(.*) 重写为 index.php.这对于大多数文件并不是特别有用.我相信你会有很多例子,因为这是一个常见问题.

The RewriteRule says to rewrite any matching url(.*) to index.php. This is not particularly useful for most files. I'm sure you'll have plenty of examples as this is a common problem.