使用.htaccess自定义URL或隐藏查询字符串

时间:2014-02-19 21:13:49

标签: php .htaccess

我是新人,我学习.htaccess。我想自定义我的网址 从 index.php?page=mobileindex/page/mobile

我使用了这段代码,但它不起作用:

RewriteEngine on
RewriteRule    ^index/([0-9]+)/?$    index.php?page=$1    [NC,L]    # Handle product requests

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

3 个答案:

答案 0 :(得分:6)

此规则应该有效:

RewriteEngine on
RewriteBase /cashearn/

RewriteCond %{THE_REQUEST} /index\.php\?page=([^\s&]+) [NC]
RewriteRule ^ index/page/%1? [R=302,L]

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

这样,您就可以在网页上显示http://domain.com/index/page/mobile的网址。

答案 1 :(得分:2)

尝试该代码:

RewriteEngine on
RewriteBase /
RewriteRule ^index/page/([^/.]+)/?$ index.php?page=$1 [L,QSA,NC]

答案 2 :(得分:0)

这应该有用 - 虽然没有经过测试

RewriteRule ^index/page/([^/.]+)$ index.php?page=$1 [L,QSA,NC]