RewriteRule htaccess根本不起作用

时间:2015-12-01 21:48:48

标签: php regex apache .htaccess mod-rewrite

我一直在尝试这几个小时观看在线教程和堆栈溢出问题,但它似乎根本不起作用。

我已在我的wamp服务器上启用了重写功能。

示例网址

http://localhost:8081/WEBSITE_URL/page.php?page=about

.htaccess内容:

Options +FollowSymLinks
RewriteEngine On

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

RewriteRule ^([a-z]+)\/?$ $1.php [NC]
RewriteRule ^page/(\w+)$ ./page.php?page=$1
RewriteRule ^page/(\w+)/$ ./page.php?page=$1

预期网址

http://localhost:8081/WEBSITE_URL/page/about/

结果是什么:

绝对没有。没有错误或错误日志,就像没有.htaccess一样。

有人能指出我正确的方向吗?

1 个答案:

答案 0 :(得分:1)

试试这个:

Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /WEBSITE_URL/

RewriteCond %{THE_REQUEST} /page\.php\?(page)=([^&\s]+) [NC]
RewriteRule ^ %1/%2/? [R=302,L]

RewriteCond %{THE_REQUEST} /([^/.]+)\.php[\s?] [NC]
RewriteRule ^ %1 [R,L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php [L]

RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^page/(\w+)/?$ page.php?page=$1 [L,QSA,NC]