.htaccess:不重写索引

时间:2014-02-06 17:23:12

标签: apache .htaccess mod-rewrite rewrite

如果1美元没有'索引',我该如何重写?

Options +FollowSymLinks +ExecCGI

<IfModule mod_rewrite.c>

RewriteEngine On
RewriteCond %{REQUEST_URI}  !/assets
RewriteRule (.*)  index.php?p=$1 [QSA]

</IfModule>

示例:

如果我去mysite.com/test,输出是

  

数组([p] =&gt;测试)

当我去mysite.com时输出是:

  

数组([p] =&gt;)

那么,当我去mysite.com时,如何将$ 1重写为'index'?像这样:

mysite.com:

  

数组([p] =&gt;索引)

1 个答案:

答案 0 :(得分:1)

使用此代码:

RewriteEngine On

RewriteCond %{REQUEST_URI} !/(assets|index\.php) [NC]
RewriteRule ^/?$ index.php?p=index [L,QSA]

RewriteCond %{REQUEST_URI} !/(assets|index\.php) [NC]
RewriteRule ^(.+)$ index.php?p=$1 [L,QSA]