【问题标题】:How to write apache rewrite mode for html?如何为html编写apache重写模式?
【发布时间】:2018-09-08 07:53:45
【问题描述】:

当有人输入http://ww.mysite.com/share.html/abcdef 时,url 应该与http://ww.mysite.com/share.html/abcdef 保持一致

但它应该被处理为http://ww.mysite.com/share.html?q=abcdef 在服务器上。

我已经尝试了以下现有解决方案,但它给了我 404 not found 错误,

RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^share.html/(.*)$ share.html?q=$1 [QSA]

【问题讨论】:

  • 尝试在您的规则中添加/。 RewriteRule ^share.html/(.*)$ share.html/?q=$1 [QSA]
  • 还是给我 404 not found
  • 没有规则你能到share.html吗?
  • "example.com/share.html?q=VpsTOrfE" 这个工作网址

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


【解决方案1】:

替换这一行:

RewriteRule ^share.html/(.*)$ share.html?q=$1 [QSA]

有了这个:

RewriteRule ^share\.html/(.*)$ share.html?q=$1 [L]

首先你应该转义 . 并添加 L 标志。

注意: QSA 标志在您的情况下没有意义,请阅读此https://httpd.apache.org/docs/2.4/rewrite/flags.html

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-04-05
    • 2012-01-29
    • 1970-01-01
    • 2017-07-25
    • 2021-11-29
    • 1970-01-01
    • 2014-04-18
    • 2016-05-16
    相关资源
    最近更新 更多