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