【问题标题】:How to remove id and title from url and rewrite it with domain followed by title name only?如何从 url 中删除 id 和 title 并用域后跟标题名称重写它?
【发布时间】:2018-06-24 20:11:09
【问题描述】:

我想从 URL 中删除 id 并用域后跟标题名称重写它,仅适用于 SEO 友好的 URL。

http://www.eyecatchers.co/testblog1.php?id=110&title=6-Benefits-of-Hiring-a-Digital-Marketing-Agency.

这是我当前的网址,我想通过.htaccess 将其重写为以下网址

http://www.eyecatchers.co/6-Benefits-of-Hiring-a-Digital-Marketing-Agency.

我试过了

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule id/(.*)/(.*)/ testblog1.php?id=$1&title=$2 
RewriteRule id/(.*)/(.*) testblog1.php?id=$1&title=$2

但它给了我

http://www.eyecatchers.co//id/110/6-Benefits-of-Hiring-a-Digital-Marketing-Agency.

如何仅获取域名和标题名称?

【问题讨论】:

  • 你有没有试过...
  • 你使用任何框架吗?
  • @AdamKozlowski 我没有使用任何框架
  • 您确定需要在网址末尾添加那个点吗?
  • @Tarasovych 抱歉,这是一句话。没必要有那个

标签: php .htaccess seo


【解决方案1】:

这个正则表达式可能会有所帮助
preg_replace("/testblog1\.php\?id=\d*&amp;title=/", "$1", $input_lines);

所以
http://www.eyecatchers.co/testblog1.php?id=123&amp;title=your-title
转为
http://www.eyecatchers.co/your-title

【讨论】:

  • 在哪里使用这个?你能详细说明一下吗?
  • @Swagatika read here。我不知道您的服务器上是否只有一个.htaccess,所以我无法给出完整的答案
猜你喜欢
  • 2017-05-18
  • 2020-09-09
  • 1970-01-01
  • 2013-07-16
  • 2015-06-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-09-07
相关资源
最近更新 更多