【问题标题】:Deleting all php extension and get rid of variables in the url删除所有 php 扩展并摆脱 url 中的变量
【发布时间】:2014-04-12 09:47:50
【问题描述】:

我得到了这个网址

/localhost/andalucia/productdetails.php?value=20

我想改成

/localhost/andalucia/productdetails/20

如何做到这一点以及如何在处理程序页面中获得值 20?

我应该更改编码还是只添加一个 ht 访问文件?

如果是添加一个ht访问文件,里面应该有什么代码?

如果我有更多页面,例如:

/localhost/andalucia/product
/localhost/andalucia/home
/localhost/andalucia/contactus

它们也会自动受到影响吗?
好的,我尝试使用

RewriteRule ^productdetails/([0-9]+)$ productdetails.php?value=$1 [L,QSA]

但现在问题是我的所有 图片 都在 html 中消失了,我无法像打开其他 页面 一样

/localhost/andalucia/product
/localhost/andalucia/home
/localhost/andalucia/contactus

我需要一个可以打开所有这些的 htaccess 代码

/localhost/andalucia/product
/localhost/andalucia/home
/localhost/andalucia/contactus
/localhost/andalucia/productdetails/20

请帮助某人

【问题讨论】:

标签: php url mod-rewrite url-rewriting get


【解决方案1】:

使用 apache 扩展 mod_rewrite 将漂亮的 URL 转换为脚本所需的 URL 非常容易。这个.htaccess 放在您的网络根目录中的示例应该可以帮助您:

RewriteEngine On

RewriteRule ^andalucia/productdetails/([0-9]+)$ /andalucia/productdetails.php?value=$1 [L]

这个例子只会重写andalucia/productdetails/NNNN...格式的网址,其他的网址不受影响。如果需要传递其他查询参数,例如/andalucia/productdetails/20?sort=asc,则需要将QSA 标志(查询字符串追加)传递给重写规则:

RewriteRule ^andalucia/productdetails/([0-9]+)$ /andalucia/productdetails.php?value=$1 [QSA,L]

L 标志将禁止评估下一个规则。只需查看mod_rewrite 文档即可进行深入讨论!

【讨论】:

  • 我复制粘贴它删除了重写规则中的安达卢西亚仍然没有找到对象我无法帮助
猜你喜欢
  • 2021-07-11
  • 1970-01-01
  • 1970-01-01
  • 2015-12-06
  • 2013-07-24
  • 2020-08-11
  • 2011-12-11
  • 1970-01-01
相关资源
最近更新 更多