【问题标题】:.htaccess replace url?.htaccess 替换网址?
【发布时间】:2012-05-10 21:29:49
【问题描述】:

我有一个这样的网址:

localhost/site/index.php?option=com_cust&tool=edit

我想将index.php?option=com_cust&tool=edit 替换为edit。这可能吗?我所做的尝试不起作用,例如:

RewriteEngine On
RewriteRule ^index.php?option=com_cust&tool=edit localhost/site/edit [L,QSA,R=301]

【问题讨论】:

标签: .htaccess


【解决方案1】:
RewriteRule ^site/edit site/index.php?option=com_cust&tool=edit [L]

你有它向后 - 重写模块所做的是它接受用户输入的内容(在本例中为“编辑”)并将其转换为您的服务器可以理解的内容(加载 index.php 并传递一堆变量)。

此外,您绝对不想要外部重定向,更不用说 301 重定向了。 'L' 应该是您在这里需要的唯一标志。

【讨论】:

  • 您好,感谢您的帮助和解释。我应用了规则,但 url 仍然没有改变?我设置了 Options +FollowSymlinks 和 RewriteEngine,所以我不知道为什么它不起作用?
  • 没问题 - 你也设置了 AllowOverrides All 吗?尝试在 .htaccess 文件中插入一些随机字符,看看是否会引发 500 错误。
  • 是的,我在 httpd 中设置了该设置,随机字符也会在网站上引发 500 错误。
  • 很抱歉 - 我没有注意到 URL 的 site 部分。我更新了我的答案,你现在可以检查一下吗?
  • 让它RewriteRule ^(site)/(edit)/?$ $1/index.php?option=com_cust&tool=$2 [L,NC,QSA]
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-01-18
  • 1970-01-01
  • 2019-08-18
  • 2018-04-24
  • 2014-07-30
  • 2012-09-15
相关资源
最近更新 更多