.htaccess url重写删除id

时间:2015-05-14 06:49:57

标签: php apache .htaccess mod-rewrite url-rewriting

是否可以使用.htaccess删除网址和参数ID只是显示文字。目前我有像

这样的网址

当前网址

http://localhost/profile.php?profileid=4554

用.htaccess重写

http://localhost/profileid-4554/My UserName

需要的网址

http://localhost/profileid/My UserName

在上面的网址中,我想删除ID 4554.我的.htaccess

RewriteEngine on
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php

RewriteRule ^profileid-([0-9]+) profile?profileid=$1

有可能吗?

3 个答案:

答案 0 :(得分:1)

你问http://localhost/profileid-4554/My UserName。我不明白你在哪里My username。但其余的可以在下一步完成

RewriteEngine on
RewriteCond %{QUERY_STRING} profileid=([^&]+)
RewriteRule profile.php /profileid-%1 [L,R]

答案 1 :(得分:1)

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

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

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

答案 2 :(得分:0)

试试这个

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

RewriteRule ^([a-zA-Z0-9_-]+)$ profile.php?url=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ profile.php?url=$1