【问题标题】:Slashes instead of $_GET variables斜线而不是 $_GET 变量
【发布时间】:2013-04-19 20:01:41
【问题描述】:

我知道这是一个已经回答的问题。问题是我不知道自己做错了什么,但是当我粘贴在另一个代码中找到的代码时:

RewriteEngine On
RewriteRule ^([^/]+)/([^/]+)$  index.php?$1=$2
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)$  index.php?$1=$2&$3=$4
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)$  index.php?$1=$2&$3=$4&$5=$6

...什么也没发生。

我只是希望网址变成这样:www.foo.com/it/5 而不是 www.foo.com?it=5

感谢您的帮助!

【问题讨论】:

  • 此类问题请使用google:google.de/…
  • 你听说过Routing mechanism吗?

标签: php .htaccess url


【解决方案1】:

这不会重写 看到的 URL,它会重写 Apache 看到的规则。

而且,这些规则很荒谬。我建议更简单的方法,例如:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f  #skip if file exists
RewriteCond %{REQUEST_FILENAME} !-d  #skip if directory exists
RewriteRule ^(.*)$ index.php?rt=$1 [L,QSA]

当有人请求时:

http://foo.com/fancy/url/here

Apache 将其 [内部] 更改为:

http://foo.com/index.php?rt=fancy/url/here

您的 PHP 脚本会看到:

$_GET['rt'] == 'fancy/url/here';

然后你可以:

$arr = explode('/', $_GET['rt']);

得到:

$arr == array('fancy','url','here')

【讨论】:

  • 我知道这是一篇旧帖子,但这些规则返回错误:/var/www/html/.htaccess: RewriteCond: bad flag delimiters
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-11-10
  • 2014-08-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多