重定向301工作HTML而不是PHP文件?

时间:2014-12-02 17:46:57

标签: apache .htaccess

我被困在这里,因为重定向无法正常工作。它适用于目录和HTML文件,但不会重定向PHP文件。

请有人指出我的错误。感谢。

ErrorDocument 404 http://www.domain.com/404.php
<ifModule mod_headers.c>
    <FilesMatch "\.(jpg|jpeg|png|gif|ico|pdf|pdf|xml|txt|css|js)$">
    Header set Cache-Control "max-age=604800, proxy-revalidate"
    </FilesMatch>
</ifModule>
<ifModule mod_expires.c>
    ExpiresActive On
    ExpiresDefault A259200

    ExpiresByType image/gif A2592000
    ExpiresByType image/png A2592000
    ExpiresByType image/jpg A2592000
    ExpiresByType image/x-icon A2592000
    ExpiresByType image/jpeg A2592000
    ExpiresByType application/pdf A2592000
    ExpiresByType application/x-javascript A604800
    ExpiresByType text/plain A604800
    ExpiresByType text/css A604800
</ifModule>

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

Redirect 301 /page.html /page/page.php?title=page 
Redirect 301 /page/ /page.php
# ^ works
Redirect 301 /page/index.php /page/page.php
Redirect 301 /page/page.php /page/page.php?title=page
# ^ doesnt work throws 404.php page

1 个答案:

答案 0 :(得分:1)

避免将mod_rewrite规则与mod_alias规则混合使用。试试这些规则:

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

RewriteRule ^communities/hamilton-info\.html$ /communities/community.php?title=Hamilton+Square [L,QSA,NC,R=302]
RewriteRule ^homesforsale/?$ /rtmi.php [L,NC,R=302]
# ^ works

RewriteRule ^communities/index\.php$ /communities/all-communities.php  [L,NC,R=302]
RewriteRule ^communities/covington-map\.php$ /communities/community.php?title=Covington  [L,QSA,NC,R=302]
# ^ doesnt work throws 404.php page

确保/communities/文件夹中没有.htaccess。