【问题标题】:need to remove & make URL shorten by using htaccess in full website需要通过在完整网站中使用 htaccess 来删除和缩短 URL
【发布时间】:2016-02-19 06:30:52
【问题描述】:

我现在的网址是:

我需要从整个网站的 URL 中删除 urlvalue3/urlvalue4/

如何使用 .htaccess 实现这一点?

目前在 .htaccess 中我正在使用:

   RewriteRule ^((!/index/cslug/).+)$ /index/cslug/$1 [L,NC] 

【问题讨论】:

  • 请发表您的尝试
  • 重写规则 ^((!/index/cslug/).+)$ /index/cslug/$1 [L,NC] @Starkeen
  • RewriteRule ^(.+)/(.+)/.+/.+/(.+)$ /index/cslug/$1/$2/$3 [L,NC](基于您的 URL 模式)
  • @Juno_okyo 你的模式永远不会匹配,因为有一个前导斜杠。
  • @Starkeen 谢谢!我被编辑了。

标签: .htaccess url-rewriting url-shortener


【解决方案1】:

您拥有(! 的正则表达式应该改为:(?!,因为它可以作为负前瞻:

RewriteRule ^((?!/index/cslug/).+)$ /index/cslug/$1 [L,NC]

接下来,替换一个由 5 部分组成的 URL:

RewriteRule ^([^/]+)/([^/]+)/[^/]+/[^/]+/([^/]+)/?$ /$1/$2/$3 [R,L]

【讨论】:

    猜你喜欢
    • 2011-03-08
    • 2020-03-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-16
    • 2016-06-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多