隐藏扩展名,并在.htaccess中用斜杠替换问号

时间:2012-12-17 14:03:44

标签: php .htaccess

我遇到了一个问题,即假设网址是www.example.com/view.php?id=1但是我想网址就像是www.example.com/view/id/1,单独我得到了htaccess隐藏扩展或替换'?'斜线,但两个都没有工作,请任何人帮助我。我想.htaccess为两者工作(扩展隐藏和替换斜线),并请使其一般是htaccess工作的任何页面,而不是任何特定的page.thanks提前

1 个答案:

答案 0 :(得分:0)

通过httpd.conf启用mod_rewrite和.htaccess,然后将此代码放在.htaccess目录下的DOCUMENT_ROOT中:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

# external redirect from /view.php?id=1 to /view/id/1
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+([^.]+)\.php\?([^=]+)=([^\s&]+) [NC]
RewriteRule ^ /%1/%2/%3? [L,R=301]

# internal forward from /view/id/1 to /view.php?id=1
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/?$ /$1.php?$2=$3 [L,QSA]