如何在.htaccess文件中写入301重定向的多个条件

时间:2015-08-27 18:44:33

标签: php apache .htaccess mod-rewrite redirect

在我的网站上,我想使用.htaccess文件制作301重定向规则和虚荣网址,我的代码是

RewriteEngine On
RewriteCond %{HTTP_HOST} ^availany.com
RewriteRule (.*) http://www.availany.com/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([^\.]+)$ $1.php [NC]
RewriteCond %{REQUEST_FILENAME} >""
RewriteRule ^([^\.]+)$ profile.php?user=$1 [L]

并在网页中显示500内部错误,我做错的位置确实建议我

1 个答案:

答案 0 :(得分:1)

你的规则如下:

RewriteEngine On

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

# skip all files and directories from rewrite rules below
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]

RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([^.]+?)/?$ $1.php [L]

RewriteRule ^([^.]+?)/?$ profile.php?user=$1 [L,QSA]