.htaccess将文件重写为文件而没有ext和文件夹到一个文件

时间:2014-01-16 16:28:03

标签: apache mod-rewrite

以下是我所说的:

localhost/add.php -> localhost/add
localhost/1234/ -> localhost/view.php?id=1234

我尝试过:

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

1 个答案:

答案 0 :(得分:0)

这是你要找的吗?

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]