0

我在http://www.mysite.com/test/中有一个 .htaccess 文件,我试图用它来将访问http://mysite.com/test/的任何人发送到http://www.mysite.com /test/但它不起作用,这是我的代码:

# Force Caching
Header unset Pragma
FileETag None
Header unset ETag
<FilesMatch "\.(ico|jpg|jpeg|png|gif|js|css|swf|pdf|flv|mp3)$">
<IfModule mod_expires.c>
 ExpiresActive on
 ExpiresDefault "access plus 14 days"
 Header set Cache-Control "public"
</IfModule>
</FilesMatch>
<FilesMatch "\.(html|htm|xml|txt|xsl)$">
 Header set Cache-Control "max-age=7200, must-revalidate"
</FilesMatch>

# Enable gzip compression
<IfModule mod_mime.c>
 AddType application/x-javascript .js
 AddType text/css .css
</IfModule>
<IfModule mod_deflate.c>
 AddOutputFilterByType DEFLATE text/css application/x-javascript text/x-component text/html text/richtext image/svg+xml text/plain text/xsd text/xsl text/xml image/x-icon application/javascript
 <IfModule mod_setenvif.c>
  BrowserMatch ^Mozilla/4 gzip-only-text/html
  BrowserMatch ^Mozilla/4\.0[678] no-gzip
  BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
 </IfModule>
 <IfModule mod_headers.c>
  Header append Vary User-Agent env=!dont-vary
 </IfModule>
</IfModule>


# Main Rewrite rules
<IfModule mod_rewrite.c>
    Options +FollowSymlinks
    RewriteEngine On
    RewriteBase /

    # Always use www.
    RewriteCond %{HTTP_HOST} !^www [NC]
    RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R]

    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
</IfModule>

有想法该怎么解决这个吗?

4

1 回答 1

1

.htaccess 文件位于/test目录中。这就是在' 请求 URL 模式/test/中删除前缀的原因。要正确重定向请求,您必须将替换更改为RewriteRule.*

RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R]
于 2013-03-13T22:45:24.977 回答