我知道有很多类似的帖子(我经历了大部分内容)但由于某种原因没有任何帮助从URL中删除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
配置文件:
inanzzz@ubuntu:/etc/apache2/sites-enabled$ sudo nano 000-default.conf
<VirtualHost *:80>
ServerAdmin webmaster@localhost
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]
答案 0 :(得分:0)
在根目录中尝试这些规则.htaccess:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} \s/+index\.php/(\S+) [NC]
RewriteRule ^ /%1 [R=301,L,NE]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+?)/?$ index.php/$1 [L]