重写规则htaccess混乱

时间:2016-08-04 07:55:33

标签: .htaccess url-rewriting

所以我是htaccess中重写规则的新手,可以使用一些帮助

我目前有一个php页面poll.php基本模板,它从PHPMyAdmin获取的信息通过pollcode获取轮询信息,这个例子它将是vmxez所以poll.php?code = vmxez正确显示我想要的它,但我试图重写它所以domain.com/vmxez显示在domain.com/poll.php?code=vmxez上的任何帮助将是伟大的战斗这2小时。

1 个答案:

答案 0 :(得分:1)

假设已安装并启用了重写模块,

# Turn on the rewrite engine
RewriteEngine On
# Set the base path
RewriteBase /
# Rewrite an exact match of /vmxez
RewriteRule ^/vmxez$ /poll.php?code=vmxez

如果您的目标实际上是将所有非PHP脚本请求发送到poll.php:

# Skip rewrites for direct file requests (e.g. PHP scripts)
RewriteCond %{REQUEST_FILENAME} !-f
# Capture the path requested and pass it as a parameter
RewriteRule ^(.+)$ /poll.php?code=$1