簡體   English   中英

通過htaccess從網址中刪除index.php

[英]Remove index.php from url by htaccess

我正在開發一個PHP框架,而我對.htaccess規則還是陌生的。 因此,我需要使用.htaccess重定向url。 網址為

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

應該轉換為此

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

在.htaccess文件中,我包括了這些規則

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

但它不起作用。 請幫忙。

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 /圖像/

如有疑問,請走Codeigniter路線!

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

基本上沒有理由在重寫規則和條件中包括URL的域部分,而您的條件看起來很時髦。 看上面的codeigniter示例,我們在表達式中需要做的就是:在路徑中找到index.php段,並刪除它,然后重寫以包含它。 您的表達式假定路徑將始終相同...如果這有意義。

請嘗試以下代碼:

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

請嘗試以下代碼。 運作正常。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM