使用localhost服务器中的htaccess删除$ _GET变量

时间:2017-03-16 09:00:51

标签: .htaccess

伙计们,你能帮助我吗?我想用htaccess清理我的网址。

http://localhost/website/index.php?page=directory&id=1

http://localhost/website/directory/1

2 个答案:

答案 0 :(得分:0)

在您的网站目录中使用以下规则

RewriteEngine On

# neither a directory nor a file

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d    
RewriteRule ^([\w-]+)/([\w-]+)$ index.php?page=$1&id=$2 [QSA,L]

答案 1 :(得分:0)

index.php
<a href="directory/1">click</a>

submit.php
<?php 
echo $_GET['id'];
echo $_GET['page'];
 ?>

.htaccess
RewriteEngine on
RewriteRule ^([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$  submit.php?page=$1&id=$2    [NC,L]