Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/256.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php .htaccess重写不起作用301redirect_Php_Apache_.htaccess_Mod Rewrite_Redirect - Fatal编程技术网

Php .htaccess重写不起作用301redirect

Php .htaccess重写不起作用301redirect,php,apache,.htaccess,mod-rewrite,redirect,Php,Apache,.htaccess,Mod Rewrite,Redirect,我在.htaccess中有以下代码来重写用户名 <IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ /profile.php?username=$1 [L] </IfModule> 为此: www.domain.com/Mike 现在我有了另一个w

我在.htaccess中有以下代码来重写用户名

<IfModule mod_rewrite.c>
 RewriteEngine On
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteRule ^(.*)$ /profile.php?username=$1 [L]

</IfModule>
为此:

www.domain.com/Mike
现在我有了另一个www 301重定向的重写规则。 这也很有效,除非我在ww.domain.com/Mike上删除了“www”,这是我在url中得到的内容:

www.domain.com/profile.php?username=Mike
我的问题是为什么我在删除“www”后没有得到相同的url:(www.domain.com/Mike)

以下是我在.htaccess中的完整代码:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /profile.php?username=$1 [L]

</IfModule>


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

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/
RewriteRule ^index\.php$ http://www.domain.com/ [R=301,L]

重新启动发动机
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则^(.*)$/profile.php?用户名=$1[L]
重新启动发动机
重写cond%{HTTP_HOST}^domain\.com[NC]
重写规则(.*)http://www.domain.com/$1[L,R=301]
重写cond%{THE_REQUEST}^[A-Z]{3,9}\/index\.php\HTTP/
重写规则^index\.php$http://www.domain.com/ [R=301,L]

更改规则的顺序,在内部重写规则之前保留301重定向规则:

RewriteEngine On

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

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/
RewriteRule ^index\.php$ http://www.domain.com/ [R=301,L]

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

谢谢你,先生,现在很好用。顺便说一句,在重新编写引擎之前是否需要添加?一旦您确保启用了
mod_rewrite
,就不需要添加。
RewriteEngine On

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

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/
RewriteRule ^index\.php$ http://www.domain.com/ [R=301,L]

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