使用Htaccess重写URL,如filename / param1 / param2等

时间:2013-06-25 13:47:22

标签: .htaccess url mod-rewrite rewrite

我正在寻找以下情况的解决方案。我想隐瞒以下网址

www.example.com/filename.php?p1=1&p2=2 etc

www.exmaple.com/filename/1/2 etc

我设法用index.php做到了这一点,但我还想使用其他文件,而不仅仅是索引。可能吗?这是我目前的代码。

Options +FollowSymlinks -MultiViews

RewriteEngine On
RewriteBase /

# add .php to access file, but don't redirect
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_URI} !/$
RewriteRule (.*) $1\.php [L]
RewriteRule ^(filename)/([^/]+)/([^/]+)$ /$1.php?p1=$2&p2=$3 [L,QSA,NC]


ErrorDocument 404 /404.php

# display no errs to user
php_flag display_startup_errors off
php_flag display_errors off
php_flag html_errors off

这适用于删除php。但是如果我在它之后添加参数,它会给我错误500

1 个答案:

答案 0 :(得分:0)

RewriteEngine On行:

下方插入此规则
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(filename)/([^/]+)/([^/]+)/?$ /$1.php?p1=$2&p2=$3 [L,QSA,NC]