.htaccess - 从 url .htaccess 重写/重定向特定单词

标签 .htaccess url mod-rewrite redirect rewrite

我有几个由 wordpress/php 生成的网址

  • http://mydomain.com/news-2/newsarticle
  • http://mydomain.com/products/category-2
  • http://mydomain.com/products/category/products-2

  • 如何使用 重写/重定向任何 url -2 到没有?结果应该是
  • http://mydomain.com/news/newsarticle
  • http://mydomain.com/products/category
  • http://mydomain.com/products/category/products

  • 这是我到目前为止
    <IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteBase /
        RewriteRule ^index\.php$ - [L]
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule . /index.php [L]
    </IfModule>
    

    谢谢

    最佳答案

    将此添加到您的 htaccess :

    RewriteRule ^(.*)-2(.*)$ /$1$2 [NC,L,R=301]
    

    关于.htaccess - 从 url .htaccess 重写/重定向特定单词,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11853657/

    相关文章:

    php短网址奇怪的外观

    c# - 在 ASP.NET MVC 2 中,我可以使用默认的 ModelBinder 将查询字符串反序列化为数组吗?

    css - 重写 htaccess 文件丢失 css 文件问题

    .htaccess - 如何使 Zend Framework 2 与 nginx 一起工作?

    .htaccess - htaccess 垂直条(管道)的重写条件

    .htaccess - 迁移到新主机后 Joomla 站点 URL 重写不起作用

    php - 使用正则表达式阻止 .htaccess 中的 URL

    networking - 如何以编程方式确定 URI、主机名或 IP 地址是否指向本地主机?

    java - 无法使用 Jsoup 解析 url 的完整 html

    php - 使用 .htaccess 在 php 中实现干净的 url