.htaccess htaccess无法删除index.php

.htaccess htaccess无法删除index.php,.htaccess,.htaccess,我使用此代码强制www并删除index.php: Options +FollowSymLinks -MultiViews # Turn mod_rewrite on RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ /index.php?id=$1 [L] RewriteCond %{THE_REQ

我使用此代码强制www并删除
index.php

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

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


RewriteCond %{THE_REQUEST} ^GET\ /(.*/)?(?:index\.php)?\?id=([^\s&]+) [NC]
RewriteRule ^ /%1%2? [R=301,L]

RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
它在centOS服务器上工作。但不是在Ubuntu 16中

它可以强制www,但不会删除
index.php


另外,我想将
example.org
重定向到
example.com

没有充分的理由说明它会在一个操作系统上部分工作,而不是在另一个操作系统上。除非以前的(错误的)重定向已被缓存

但是,您的指令顺序错误。内部重写(前端控制器)需要在Canonical重定向之后进行,否则它在请求“虚拟URL”时将永远不会“强制www”或“删除
index.php

例如:

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

RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

RewriteCond %{THE_REQUEST} ^GET\ /(.*/)?(?:index\.php)?\?id=([^\s&]+) [NC]
RewriteRule ^ /%1%2? [R=301,L]

# Front controller should be after canonical redirects
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?id=$1 [L]
我还想将example.org重定向到example.com

在上述重定向之前添加以下内容:

RewriteCond %{HTTP_HOST} ^(www\.)?example\.org [NC]
RewriteRule ^ https://example.com%{REQUEST_URI} [R,L]

您需要在测试之前清除浏览器缓存。

没有充分的理由说明它会在一个操作系统上部分工作,而不是在另一个操作系统上。除非以前的(错误的)重定向已被缓存

但是,您的指令顺序错误。内部重写(前端控制器)需要在Canonical重定向之后进行,否则它在请求“虚拟URL”时将永远不会“强制www”或“删除
index.php

例如:

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

RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

RewriteCond %{THE_REQUEST} ^GET\ /(.*/)?(?:index\.php)?\?id=([^\s&]+) [NC]
RewriteRule ^ /%1%2? [R=301,L]

# Front controller should be after canonical redirects
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?id=$1 [L]
我还想将example.org重定向到example.com

在上述重定向之前添加以下内容:

RewriteCond %{HTTP_HOST} ^(www\.)?example\.org [NC]
RewriteRule ^ https://example.com%{REQUEST_URI} [R,L]
在测试之前,您需要清除浏览器缓存