【问题标题】:htaccess rewrite rule for url varible as parent folderurl变量的htaccess重写规则作为父文件夹
【发布时间】:2018-11-15 10:07:41
【问题描述】:

我已经在我的文件夹中创建了一个 .htaccess,并希望创建 URL:

www.example/good/page

朝向:

www.example/page?type=good

我当前的文档写成:

RewriteRule ^(\w+)$\/page page.php?type=$1 [NC,L]

但是没用,不知道怎么检查是否正确

谁能为此提供一些例子? 谢谢!

【问题讨论】:

  • RewriteRule ^type/([^/]*)$ /page?type=$1 [L]

标签: php .htaccess redirect url-rewriting


【解决方案1】:

确保您的重写引擎已打开,并且它正在重写基础。更改您的代码,如下所示:

RewriteEngine on
RewriteBase /

RewriteRule ^/?([^/]+)/page?$ "page.php?type=$1" [L,QSA]

然后你的重写规则必须看起来像这样。

RewriteRule 基本上意味着如果完成的请求匹配^/?([^/]+)/page?$(匹配除服务器根以外的任何URL),它将被重写为page.php?type=$1,这意味着对page.php 的请求被重写为page.php?type=good )。

QSA 表示如果有一个查询字符串与原始 URL 一起传递,它将附加到重写(example.com/good/page?id=2 将被重写为page.php?type=good&id=2

L 表示如果规则匹配,则不再处理该规则以下的任何 RewriteRules。

试试这个,让我知道。如果对您有用,请接受答案。

【讨论】:

  • 谢谢你的回答,虽然我仍然无法得到我想要的结果。我想知道 example.com/good/page.html 的目录是否真的存在会影响结果吗?现在的 htaccess 是这样的: order allow,deny deny from all meet all RewriteEngine on RewriteBase / RewriteCond %{REQUEST_FILENAME } !-d RewriteCond %{REQUEST_FILENAME}\.php -f RewriteRule ^/?([^/]+)/page?$ "page.php?type=$1" [L,QSA]
  • @MichaelC 请使用您当前版本的 .htaccess 文件更新问题。因为我的答案是经过测试的。您的重写条件必须使其行为不同。
猜你喜欢
  • 2017-07-16
  • 2016-03-30
  • 2012-08-20
  • 2017-07-08
  • 2012-01-16
  • 1970-01-01
  • 2012-11-22
  • 1970-01-01
  • 2012-02-24
相关资源
最近更新 更多