Apache .htaccess将文件重写为不带ext的文件,将文件夹重写为一个文件

Apache .htaccess将文件重写为不带ext的文件,将文件夹重写为一个文件,apache,mod-rewrite,Apache,Mod Rewrite,以下是我所说的: localhost/add.php -> localhost/add localhost/1234/ -> localhost/view.php?id=1234 我所尝试的: RewriteRule (.*)$ /view.php?id=$1 RewriteRule (.*) $1.php [L] 这就是你要找的吗 Options -MultiViews RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-d R

以下是我所说的:

localhost/add.php -> localhost/add
localhost/1234/ -> localhost/view.php?id=1234
我所尝试的:

RewriteRule (.*)$ /view.php?id=$1
RewriteRule (.*) $1.php [L]

这就是你要找的吗

Options -MultiViews
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [L]

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