网址重写的htaccess问题

时间:2013-12-27 11:06:20

标签: .htaccess

这是我的htaccess文件:

Options -Multiviews

RewriteEngine on
RewriteBase /

RewriteRule ^index.php$ / [L,R=301]
RewriteRule ^(.+)/index.php$ /$1/ [L,R=301]

这已经成功删除了index.php但是离开了吗?在查询字符串之前

http://example.com/?type=1

如何删除此'?'使用htaccess

另外,我怎样才能将上面的url显示为:

http://example.com/type/1

2 个答案:

答案 0 :(得分:1)

RewriteEngine on
RewriteRule ^type/([^/.]+)/?$ index.php?type=$1 [L]

工作原理

RewriteRule ^type/([^/.]+)/?$表示它将您的路径的网址设置为type/5*/ * =其中包含的数字。

然后,新网址中提供的信息会将其传递给索引页面。 (index.php?type=$1 [L]

例如,如果您有类型/ 1,它会转发到index.php?type = 1

我希望这有助于您和您现在对其工作原理有更广泛的了解。

答案 1 :(得分:0)

尝试以下方法;

RewriteEngine On
RewriteRule ^type/([^/]*)$ /index.php?type=$1 [L]
相关问题