Apache .htaccess www重定向无法正常工作

Apache .htaccess www重定向无法正常工作,apache,.htaccess,mod-rewrite,redirect,http-status-code-301,Apache,.htaccess,Mod Rewrite,Redirect,Http Status Code 301,我想重定向我的网站 www.example.com to example.com 我在ht access文件中使用以下代码: Options +FollowSymlinks RewriteEngine on RewriteCond %{REQUEST_URI} ^/[\w]+/www/(.*)$ RewriteCond %{DOCUMENT_ROOT}/applications/%{REQUEST_URI} -f RewriteRule ([\w]+\/www\/(.*)) /appli

我想重定向我的网站

www.example.com to example.com
我在ht access文件中使用以下代码:

Options +FollowSymlinks

RewriteEngine on


RewriteCond %{REQUEST_URI} ^/[\w]+/www/(.*)$
RewriteCond %{DOCUMENT_ROOT}/applications/%{REQUEST_URI} -f
RewriteRule ([\w]+\/www\/(.*)) /applications/$1 [NC,L,E=STOP:1]
#RewriteRule .* - [NC,L]


# Internal ENVs are prefixed with REDIRECT_
RewriteCond %{ENV:REDIRECT_STOP} !1

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


RewriteCond %{HTTP_HOST} ^www\.example\.com [NC]
RewriteRule ^(.*) http://example.com/$1 [L,R=301]
它工作得很好,只是不太好

当它重定向时,它会执行以下操作:

www.example.com > example.com/index.php?/
www.example.com/page/ > example.com/index.php?/page/

index.php?
部分从何而来,我如何摆脱它?

规则的顺序是个问题。在内部重写规则之前保留重定向规则:

选项+FollowSymlinks

RewriteEngine on

RewriteCond %{HTTP_HOST} ^www\.example\.com [NC]
RewriteRule ^(.*) http://example.com/$1 [L,R=301]

RewriteCond %{REQUEST_URI} ^/[\w]+/www/(.*)$
RewriteCond %{DOCUMENT_ROOT}/applications/%{REQUEST_URI} -f
RewriteRule ([\w]+\/www\/(.*)) /applications/$1 [NC,L,E=STOP:1]
#RewriteRule .* - [NC,L]

# Internal ENVs are prefixed with REDIRECT_
RewriteCond %{ENV:REDIRECT_STOP} !1

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

非常感谢你。工作完美。