htaccess有php扩展的重定向循环错误

时间:2015-04-09 16:41:47

标签: .htaccess mod-rewrite

我的htaccess

Options -Indexes +FollowSymLinks
RewriteEngine On

RewriteBase /
DirectorySlash Off
AddDefaultCharset UTF-8
SetEnv TZ Asia/Bsngkok
DefaultLanguage th
ContentDigest On
SetEnv SERVER_ADMIN aaa@aaa.com

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

##### Add trailing slash ####################################
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://www.aaa.com/$1/ [R=301,L]

RewriteRule ^(.*)/$ /$1.php [L]
RewriteRule ^audio/([^/\.]+)/?$ /pages/viewAudio.php?id=$1 [L]

<filesMatch "\.(ttf|woff|woff2|eot)$">
    Header set Cache-Control "max-age=2592000, public"
</filesMatch>

<filesMatch ".(php|cgi)$">
    Header set Cache-Control "max-age=0, private, no-store, no-cache, must-revalidate"
</filesMatch>

<files .htaccess>
    order allow,deny
    deny from all
</files>

当我转到http://www.aaa.com/audio/test它的循环并有很多像http://www.aaa.com/audio/test.php.php.php.php.php.php.php.php.php.php.php.php.php.php.php.php.php.php.php.php/这样的PHP但我想要http://www.aaa.com/audio/test

1 个答案:

答案 0 :(得分:0)

那是我的方式。我改变逻辑,它工作正常

<IfModule mod_rewrite.c>
    Options +FollowSymlinks -MultiViews -Indexes
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME}\.php -f
    RewriteRule ^([^/]+)/$ $1.php 

    # Forces a trailing slash to be added
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
    RewriteRule (.*)$ /$1/ [R=301,L]

    #CustomURL With parameter
    RewriteRule ^audio/([A-Za-z-\s0-9]+)/$ /pages/viewAudio.php?slug=$1 [L]
</IfModule>