[英]htaccess redirect error to a subdirectory
Trying to redirect this always works: 尝试重定向此方法始终有效:
RewriteRule ^user/(.*) view_channel.php?user=$1 [nc]
The problem, trying to redirect the statement below alone works but when combined with the above statement it doesn't work (the result was a blank page): 问题是,尝试单独重定向下面的语句有效,但是当与上面的语句结合使用时,它不起作用(结果是空白页):
RewriteRule ^user/videos/(.*) user_videos.php?user=$1 [nc]
More details about .htaccess: 有关.htaccess的更多详细信息:
Options All -Indexes
FileETag MTime Size
Options +FollowSymlinks -MultiViews
RewriteEngine on
<FilesMatch "\.(db|inc|tmpl|h|ihtml|sql|ini|configuration|config|class|bin|spd|theme|module|cfg|cpl|tmp|log|err|inc.php|class.php)$">
order allow,deny
satisfy all
</FilesMatch>
What am I doing wrong? 我究竟做错了什么?
The rules are not mutually incompatible. 规则不是相互不兼容的。 Nor are they final. 他们也不是最终的。 Change them like this: 像这样更改它们:
RewriteRule ^user/([^/]+) view_channel.php?user=$1 [NC,L]
RewriteRule ^user/videos/([^/]+) user_videos.php?user=$1 [NC,L]
[^/]+
matches one or more character that is not a /
. [^/]+
匹配一个/
而不是/
字符。 This ensures that the first rule cannot match the second pattern, which it did with the .*
, as that matches any characters, including /
of course. 这样可以确保第一个规则不能匹配第二个模式,因为它匹配.*
,因为它可以匹配任何字符,包括/
。
It is because your regex ^user/(.*)
also matches a URI like /user/videos/something
. 这是因为您的正则表达式^user/(.*)
也匹配URI,如/user/videos/something
。
Have your rules like this: 有这样的规则:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
RewriteRule ^user/videos/([^/]+)/?$ user_videos.php?user=$1 [L,NC,QSA]
RewriteRule ^user/([^/]+)/?$ view_channel.php?user=$1 [L,QSA,NC]
第二个RewriteRule
语句与已经重写的url相匹配。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.