其實上次就有提到了
如果要排除的檔案太多, 試試看用檔案是否存在當條件
<pre class="c" name="code">
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?cat1=$1
還有你貼的那一行, $1 是什麼東西得要看你其它地方怎樣寫
光貼一行沒辦法知道的
目前使用
<pre class="c" name="code">RewriteEngine On
RewriteRule ^css($|/) - [L,NC]
RewriteCond $1 !^(index\.php|img|adm)
RewriteRule ^([^/]*)$ index.php?cat1=$1
RewriteRule ^([^/]*)/([^/]*)$ index.php?cat1=$1&cat2=$2
RewriteRule ^([^/]*)/([^/]*)/([^/]*)$ index.php?cat1=$1&cat2=$2&cat3=$3
RewriteRule ^([^/]*)/([^/]*)/([^/]*)/([^/]*)$ index.php?cat1=$1&cat2=$2&cat3=$3&cat4=$4
RewriteRule ^([^/]*)/([^/]*)/([^/]*)/([^/]*)/([^/]*)$ index.php?cat1=$1&cat2=$2&cat3=$3&cat4=$4&cat5=$5
發現adm/adm.php會像其他要rest的一樣被拆成adm和adm.php
使用
<pre class="c" name="code">
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]*)$ index.php?cat1=$1
RewriteRule ^([^/]*)/([^/]*)$ index.php?cat1=$1&cat2=$2
RewriteRule ^([^/]*)/([^/]*)/([^/]*)$ index.php?cat1=$1&cat2=$2&cat3=$3
RewriteRule ^([^/]*)/([^/]*)/([^/]*)/([^/]*)$ index.php?cat1=$1&cat2=$2&cat3=$3&cat4=$4
RewriteRule ^([^/]*)/([^/]*)/([^/]*)/([^/]*)/([^/]*)$ index.php?cat1=$1&cat2=$2&cat3=$3&cat4=$4&cat5=$5
則會導致連index.php和css都沒排除到
看到你這一大串...我有個建議
這是以前在 zend framework 看到的作法, 基本原理跟我提的一樣, 只是更完整些
.htaccess:
<pre class="c" name="code">
RewriteEngine On
# pass exists file
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
# rewrite all others to index.php
RewriteRule ^.*$ index.php [NC,L]
然後在 php 裡面這樣取得變數
<pre class="c" name="code">
<?php
$cat = array_map(urldecode, split("/", $_SERVER["REQUEST_URI"]));
echo "cat1 = {$cat[1]}<br>";
echo "cat2 = {$cat[2]}<br>";
echo "cat3 = {$cat[3]}<br>";
另外你的寫法, 似乎是搞錯 RewriteCond 的運作方式了
RewriteCond 只會作用在下面的"一條" RewriteRule
而不會作用在下面"所有的" RewriteRule
隨手GOOGLE了一下,找到這個,看看行不行
http://bbs.phpchina.com/thread-182777-1-1.html