总结
豆包 AI 助手文章总结

php url

php中文网
发布: 2016-06-23 13:01:24
原创
1070人浏览过

这功能要怎么实现
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文件实例

<IfModule mod_rewrite.c>  Options +FollowSymlinks  RewriteEngine On  RewriteRule ^/?$ /index.php/Api/PcOrder [L]  RewriteCond $1 !^/?index.php  RewriteCond $1 !^/?Public/  RewriteCond $1 !^/?robots.txt$</IfModule>
登录后复制

其中 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还会跳转?

PHP速学教程(入门到精通)
PHP速学教程(入门到精通)

PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
豆包 AI 助手文章总结
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号