2013-12-19 142 views
0

我正在開發一個php框架工作,我是.htaccess規則的新手。所以我需要使用.htaccess重定向 網址。鏈接從url中刪除index.php htaccess

http://localhost/rinocabs/index.php?/Galary/Image/ 

應在.htaccess文件轉換爲這個

http://localhost/rinocabs/Galary/Image/ 

我包括這些規則

Options +FollowSymlinks 
RewriteEngine on 
rewritecond %{http_host} ^localhost/rinocabs/index.php?/Galary/Image/ [nc] 
rewriterule ^(.*)$ http://localhost/rinocabs/Galary/Image/$1 [r=301,nc] 

,但它不工作。請幫忙。

回答

4
Options +FollowSymLinks -MultiViews 
# Turn mod_rewrite on 
RewriteEngine On 
RewriteBase/

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

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s(.*)/index\.php [NC] 
RewriteRule^%1 [R=301,L] 

/rinocabs/index.php的/ Galary /圖像/

本地主機/ rinocabs /的index.php?/ Galary/Image/

+0

有用。很好,但是對我的問題沒有幫助。謝謝 –

+0

你用'RewriteCond%{THE_REQUEST}^[AZ] {3,} \ s( 。*)/ index \ .php?[NC]' – sas

+0

我對你的代碼很感興趣,我對htaccess代碼有新意,請你一行一行解釋一下這個代碼:) 我得到了這樣的結果 localhost/rinocabs/index.php?/ Galary/Image /結果爲 localhost/rinocabs/ –

0

When in doubt, go the Codeigniter route!

RewriteEngine on 
RewriteCond $1 !^(index\.php|images|robots\.txt) 
RewriteRule ^(.*)$ /index.php/$1 [L] 

基本上沒有理由應包括的內容將是在重寫規則和條件您的網址的域名部分,和你的病情正在時髦。查看上面的codeigniter示例,我們需要在表達式中完成以下操作:在路徑中查找index.php段,並將其除去,然後重寫以包含它。你的表情假設道路將永遠是相同的......如果這是有道理的。使用localhost代替

+0

感謝您的回答。我去檢查這一點。要嘗試這個代碼,我必須重新啓動服務器? –

+0

事實上,它必須接受你的改變。儘管服務器重啓很簡單。 – Zarathuztra

+0

這對我不起作用:( –

0

請嘗試以下代碼:

RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} -s [OR] 
RewriteCond %{REQUEST_FILENAME} -l [OR] 
RewriteCond %{REQUEST_FILENAME} -d 
RewriteRule ^.*$ - [NC,L] 
RewriteRule ^.*$ index.php [NC,L] 
0

請嘗試下面的代碼。它工作正常。

RewriteEngine on 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule .* index.php/$0 [PT,L] 
+0

這會重寫任何URL到index.php OP會以相反的方式威脅它! –

+0

謝謝我的朋友。我已經解決了這個問題。謝謝 –