【问题标题】:Url rewrite with underline automaticly网址自动改写下划线
【发布时间】:2015-11-04 02:07:27
【问题描述】:

我正在尝试从

自动重写 url
www.example.com/test.php?title=123jane

www.example.com/test_123jane

我正在使用

RewriteRule    ^test_([A-Za-z0-9-]+)/?$    test.php?title=$1    [NC,L]'

但这不会自动改变它。

【问题讨论】:

  • 你想使用漂亮的 URL 吗?如果是这样,你有你的往返上方,对吧?

标签: apache .htaccess mod-rewrite url-rewriting friendly-url


【解决方案1】:
RewriteEngine On

RewriteCond %{THE_REQUEST} ^GET\ /test\.php\?title=([a-z0-9]+) [NC]
RewriteRule ^test\.php$ /test_%1? [R=301,L,NC]

RewriteRule ^test_([a-z0-9]+)$ /test.php?title=$1 [L]

以上应该可以。

【讨论】:

  • 我试过这个,但它写的 url 不正确。它看起来像这样:http://www.example.com/test_123jane?title=123jane
  • @RustamzadeMahammad 更新了我的回复。在上面的重写中忘记在%1 之后添加?
  • @RustamzadeMahammad 清除您的浏览器缓存(按 Ctrl + F5;或检查您的浏览器开发工具)。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-06-05
  • 1970-01-01
  • 2017-10-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多