0
我知道有很多類似的帖子(我通過其中大部分),但由於某種原因,沒有什麼幫助從URL中刪除index.php。從htaccess中刪除index.php
這些:
http://www.example.com/index.php/about
http://example.com/index.php/about
應該變成:
http://www.example.com/about
http://example.com/about
我已經運行:sudo a2enmod rewrite
配置文件:
[email protected]:/etc/apache2/sites-enabled$ sudo nano 000-default.conf
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot /var/www/html
<Directory /var/www/html/>
Options Indexes FollowSymLinks MultiViews
# changed from None to FileInfo
AllowOverride FileInfo
Order allow,deny
allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
一些我嘗試的解決方案:
1)Link
RewriteEngine On
RewriteRule ^index\.php$/[R=301,L]
RewriteRule ^(.*)/index\.php$ /$1/ [R=301,L]
2)Link
Options +FollowSymlinks -MultiViews
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{REQUEST_URI} ^(.*/)index\.html$ [NC]
RewriteRule . http://www.%{HTTP_HOST}%1 [R=301,NE,L]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule . http://www.%{HTTP_HOST}%{REQUEST_URI} [NE,R=301,L]
RewriteCond %{REQUEST_URI} ^(.*/)index\.php$ [NC]
RewriteRule . %1 [R=301,NE,L]
3)Link
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\.php$ /$1 [L,R=301]
4)Link
RewriteEngine On
RewriteCond %{REQUEST_URI} index.php
RewriteRule ^(.*)index.php$ /$1/ [R=301,L]
5)Link此返回500內部服務器錯誤
Options +FollowSymLinks -MultiViews
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]
爲什麼你不使用'^重寫規則指數\ .PHP /(.+)/ $ 1 [R = 301,L]'爲最前一頁部分? – Croises 2014-11-22 16:44:27
@anubhava - 無論如何5號都是你的,而且這個回報也是500。 – BentCoder 2014-11-22 16:45:43
@inanzzz:檢查Apache error.log以查看實際錯誤是什麼。 – anubhava 2014-11-22 16:47:12