PHP 重写网址不起作用


PHP Rewriting Url Not working

在这里,我遇到了重写url的问题。我正在使用 php(版本 5.0 以上)和 xampp。

我当前的网址是
原始网址 :/localhost/test/signup.php
重定向网址 :/localhost/test/signup/

我在 htdocs 中编写了重写规则

  RewriteEngine On
  RewriteBase /test/
  RewriteRule ^signup/$ signup.php

它不起作用。我也更改了httpd.conf设置。但没有用。

使用以下工作代码来隐藏.php扩展。

RewriteEngine On
# Unless directory, remove trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/$ http://example.com/folder/$1 [R=301,L]
# Redirect external .php requests to extensionless url
RewriteCond %{THE_REQUEST} ^(.+)'.php([#?][^' ]*)?' HTTP/
RewriteRule ^(.+)'.php$ http://example.com/folder/$1 [R=301,L]
# Resolve .php file for extensionless php urls
RewriteRule ^([^/.]+)$ $1.php [L]

你得到什么错误?

同时,您可以尝试使用这个

RewriteEngine On
RewriteBase /test/
RewriteRule ^(signup)$ signup.php [L]

对于所有 PHP 文件:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*) $1.php [L]