【发布时间】:2016-08-10 00:30:35
【问题描述】:
好的,我的 htaccess 代码已经完成了一定程度的工作……现在我被困住了。
这里是原始网址:
example.com/search/store_info.php?store=113&dentist=Dr.%20John%20Doe
我想要实现的是一个干净的 URL,没有像这样的点/句点或空格 (%20):
example.com/search/113/dr-john-doe
但是,使用我当前使用的 htaccess 代码,我得到了以下结果:
example.com/search/113/dr.
医生的姓名是从数据库中提取的,每个“博士”后面都有一个点 (.),因此从某种意义上说,这是流程停止的地方。我猜是因为点?
这是我拥有的 htaccess 代码:
RewriteEngine On
RewriteBase /search/
RewriteCond %{THE_REQUEST} /store_info\.php\?store=([a-z0-9]+)&dentist= ([a-z0-9]+) [NC]
RewriteRule ^ %1/%2/? [R=301,L]
RewriteRule ^([a-z0-9]+)/([a-z0-9]+)/?$ store_info.php?store=$1&dentist=$2 [QSA,L,NC]
【问题讨论】:
-
错误的做法。您的网页首先应该只包含干净的网址,然后您将它们转换回“丑陋”的网页以供内部使用。
-
@MarcB 如果我不使用 htaccess 代码,我正在尝试生成干净的 URL,它看起来像
example.com/search/store_info.php?store=113&dentist=Dr.%20John%20Doe但我提供的 htaccess 代码会截断牙医的全名点 -
@anubhava 当我将其推送到现场时,该代码可以在我这边运行...但是它显示的 URL 为
example.com/search/113/dr.,而不是医生的全名。 -
你确定
dentist=后面有空格吗? -
@anubhava 当我在
dentist=之后添加空格时,它会引发错误,但是,如果没有空格,则 URL 有效,但它只显示example.com/search/113/dr.而不是这个example.com/search/113/dr-john-doe你知道吗我是说?
标签: apache .htaccess mod-rewrite url-rewriting