【问题标题】:RewriteRule not working with .htaccessRewriteRule 不适用于 .htaccess
【发布时间】:2014-07-08 17:42:23
【问题描述】:

在做了一些研究后,我仍然不确定为什么这个重写规则在我的服务器上不起作用,我检查了多个主机,但无济于事,问题出在:-

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]

上面的最后一行没有为 index.php 上的 GET 提供任何东西,这意味着 $_GET 是空的。有什么建议吗?

PS:尝试实现这个 -> https://github.com/panique/php-mvc/blob/master/.htaccess

【问题讨论】:

  • 你能显示你要测试的 URL 吗?

标签: php apache .htaccess mod-rewrite


【解决方案1】:

您的规则看起来不错。尝试一些调整:

Options -Multiviews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.+)/?$ index.php?url=$1 [L,NE]

【讨论】:

  • 很高兴它有帮助。谢谢! :)
【解决方案2】:

试试这个:

Options +FollowSymlinks
RewriteEngine on

# check existing maps or files
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.* - [L]

# re-writing
RewriteRule (.*)$ index.php?url=$1

要获取 URL,您可以在 PHP 中使用类似的东西:

$linkArray = explode("/",$_GET['url']);

您仍然可以访问您的 GET 参数。如果您使用 www.mywebsite.com/home/&message=hello,它会将其重写为 www.mywebsite.com/?url=home/&message=hello。因此,通过explode,您可以获得您的URL 参数,例如使用$_GET['message'] 您可以获得消息。

【讨论】:

  • 感谢您的评论,您建议的更改无效。我不知道潜在的问题是什么
猜你喜欢
  • 1970-01-01
  • 2016-04-09
  • 1970-01-01
  • 1970-01-01
  • 2016-09-05
  • 2019-03-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多