【问题标题】:Yii and .htaccess redirectYii 和 .htaccess 重定向
【发布时间】:2014-02-13 08:40:39
【问题描述】:

我想将页面从 my_site.com/gamenews.php?id={ID} 重定向到 my_site.com/news/{ID}/,但可以't :(

我的 .htaccess 文件:

Options +FollowSymLinks
RewriteEngine on

RewriteRule ^(.*)/index\.php /$1/index [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule . index.php
RewriteRule ^gamenews\.php\?id=(.*) /news/$1/ [L,R]
AddDefaultCharset UTF-8

显示的错误:

无法处理请求“gamenews.php”

我做错了什么?谢谢。

【问题讨论】:

  • 你的问题对吗?

标签: php .htaccess redirect yii


【解决方案1】:

这样试试

RewriteRule ^news/([0-9]+)/ gamenews.php?id=$1[L,R]
  1. 重写后的 url 应该先行
  2. [0-9]表示第二个参数应该是数字

【讨论】:

  • Euh.. 你想用RewriteRule ^(.*)/index\.php /$1/index [R=301,L] 达到什么目的?
  • 忽略我的回答。我误解了这个问题。这是一个可能有帮助的链接stackoverflow.com/questions/20377530/…
  • 我想为搜索引擎重定向。
【解决方案2】:

除了语法之外,您的 htaccess 规则的顺序可能是您的问题。除非我误解了你的问题。

在你的 htaccess 中试试这个。

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^news/(.*) gamenews.php?id=$1 [L]

RewriteRule ^(.*)/index\.php /$1/index [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
AddDefaultCharset UTF-8

【讨论】:

  • 无法处理请求“gamenews.php”
猜你喜欢
  • 2013-12-30
  • 1970-01-01
  • 1970-01-01
  • 2017-07-15
  • 2014-10-19
  • 2014-07-19
  • 2012-02-03
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多