【问题标题】:.htaccess RewriteRule not working, bad flag delimiters.htaccess RewriteRule 不起作用,标志分隔符错误
【发布时间】:2015-04-24 20:52:49
【问题描述】:

我的网站以前使用这样的 URL:/folder/page

以前,您可以在 URL 中添加“面板”来编辑当前页面:/panel/folder/page

我们升级了 CMS,编辑页面的新 URL 格式如下:/panel/#/pages/show/folder/page

我正在尝试添加一个重写规则,以便我们仍然可以使用旧方法,但无法使其正常工作:

RewriteCond %{REQUEST_URI} !^/panel/#/
RewriteRule /panel(.*) /panel/#/pages/show/$1

有没有办法做到这一点?我认为 301 重定向也应该有效。

编辑:这是我现有的 .htaccess:

RewriteEngine on

RewriteBase /

# make panel links work
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^panel/(.*) panel/index.php [L]

# make site links work
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) index.php [L]

【问题讨论】:

  • 您无法解析或重写主题标签,因为它只是客户端。无论如何,您可以使用主题标签进行重定向。你可以用这条规则替换你的两行:RewriteRule ^panel/(.+)$ /panel/#/pages/show/$1 [R=301,L,NE]
  • 感谢您的回答。不幸的是,这似乎不起作用,它破坏了客户端的一些东西。
  • 如果它重定向到 CMS 需要的路径,它怎么能破坏任何东西?
  • RewriteRule "^/?panel/([^\#]+)$" "/panel/#/pages/show/$1" [R=301,L,NE] wo RewriteCond
  • @Deadooshka 导致重定向循环

标签: apache .htaccess mod-rewrite url-rewriting pretty-urls


【解决方案1】:

由于已经使用了“面板”,我最终使用了这个重定向规则:

RedirectMatch 301 /admin(.*) /panel/#/pages/show/$1

【讨论】:

    猜你喜欢
    • 2015-02-04
    • 2017-10-04
    • 2015-11-03
    • 1970-01-01
    • 2014-01-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-23
    相关资源
    最近更新 更多