localhost/china 访问到 localhost/showservices.php?id=26
現時頁面的路徑是顯示它的頁面id;客人希望能夠在後台加上新功能,可自訂路徑的名字,當更改了路徑後,前台不會看到 ‘’id=xx’’,輸入新路徑時會自動連結到對應的頁面例子localhost/showservices.php?id=26改成localhost/china但仍然是連接到 showservices.php?id=26 的位置
回复讨论(解决方案) localhost/china 访问到 localhost/showservices.php这个可以实现的
但是如果要用到id参数的话就要另外处理了 要不走post 要不通过其他方式传值过去 你仔细看你的这个帖子的url
http://bbs.csdn.net/topics/391966541 实际上391966541就是你的帖子的id 只不过他重新过了而已
如果要使用url重写 也就是伪静态
apache服务器需开启对应的rewrite模块 nginx也有相应的地方
如果是apache 一般重写的规则建议用.htaccess文件写在你的项目入口文件处 以下是一个apache .htaccess文件实例
options +followsymlinks rewriteengine on rewriterule ^/?$ /index.php/api/pcorder [l] rewritecond $1 !^/?index.php rewritecond $1 !^/?public/ rewritecond $1 !^/?robots.txt$
其中 rewriteengine on下面即为重写部分 需要用到正则表达式 详细的还的楼主自己去了解 希望能帮到你
localhost/china 访问到 localhost/showservices.php?id=26
问题是china 这个不是固定的 一个id对应一个url
localhost/jan 要访问到 localhost/showservices.php?id=6
localhost 下面还有 php文件 没法区分
localhost/xxx
xxx 没有 .php 访问到 localhost/showservices.php
这个.htaccess文件要怎么写?
创建并命名为.htaccess文件
文件内容如下
rewriteengine on
rewriterule ^/china$ /showservices.php?id=26 [l]
你需要确保服务器有开启rewrite与支持.htaccess
参考:
http://blog.csdn.net/fdipzone/article/details/8762507
http://blog.csdn.net/fdipzone/article/details/8743940
localhost/china 访问到 localhost/showservices.php?id=26
问题是china 这个不是固定的 一个id对应一个url
localhost/jan 要访问到 localhost/showservices.php?id=6
localhost/xxx
xxx 没有 .php 访问到 localhost/showservices.php
这个.htaccess文件要怎么写?
三个字母组合,不少于 2600 种
四个字母组合,不少于14950 种
.....
你是打算把 apache 累死,还是打算让自己打字打疯?
你这种还不如直接跳到一个固定地址,然后根据路径再跳转。
用rewrite不适合匹配全部不适合
暴力点,直接301过去不行吗?
我发邮件问技术负责人,他就回复
yes, you can do with htaccess feature, details as below:
1. create the table to store the mapping records
2. create the record based section to manage the mapping records
3. one create / update the record, will regenerate the htaccess file
翻译后我没明白什么意思
他的意思使用.htaccess用rewrite
不过我不建议。因为你匹配的太多了
应该先跳入一个公用页面,再跳转。
yes, you can do with htaccess feature, details as below:
1. create the table to store the mapping records
创建表来存储映射记录
这就一般短网址的处理方式一样了
2. create the record based section to manage the mapping records
通过前缀来管理,实质上与 1 是一致的
3. one create / update the record, will regenerate the htaccess file
你也可以从映射表创建 .htaccess 文件
url 重写一般不宜超过 20 条规则,尤其是写在 .htaccess 中的
每次访问都要从硬盘加载并解析,并不管是否用到用不到
rewriteengine on errordocument 404(.*) showservices.php?url=$1
如何获取不存在页面参数?
localhost/test/ch1
ch1 是不存在的 获取该参数 showservices.php?url=ch1
上面是不行的
rewriteengine on
rewritecond %{query_string} !^(.php)
rewriterule ^(.*)$ showservices.php?url=$1 [qsa,pt,l]
后缀有 .php还会跳转?