我有一个类似https://yoursitename.com的网站。我正在使用.htaccess
文件进行重定向。 .htaccess
文件中的代码如下:
RewriteRule ^websites/all /filter.php?module=1&filter=all [R=301,NC,P]
但重定向会转到另一个具有以下htaccess代码的页面:
RewriteRule ^([a-zA-Z0-9_-]+)$ show-detail.php?c=$1
我做错了什么?
.htaccess
档案的内容
RewriteEngine on
RewriteBase /
RewriteRule ^websites/all /filter.php?module=1&filter=all [R=301,NC,P]
RewriteRule ^websites/established /filter.php?module=1&filter=established [R=301,NC,P]
RewriteRule ^websites/starter /filter.php?module=1&filter=starter [R=301,NC,P]
RewriteRule ^websites/active /filter.php?module=1&filter=active [R=301,NC,P]
RewriteRule ^websites/ending /filter.php?module=1&filter=ending [R=301,NC,P]
RewriteRule ^websites/justsold /filter.php?module=1&filter=justsold [R=301,NC,P]
RewriteRule ^websites/dealflow /filter.php?module=1&filter=dealflow [R=301,NC,P]
RewriteRule ^domains/all /filter.php?module=2&filter=all [R=301,NC,P]
RewriteRule ^domains/auction /filter.php?module=2&filter=auction [R=301,NC,P]
RewriteRule ^domains/active /filter.php?module=2&filter=active [R=301,NC,P]
RewriteRule ^domains/ending /filter.php?module=2&filter=ending [R=301,NC,P]
RewriteRule ^domains/justsold /filter.php?module=2&filter=justsold [R=301,NC,P]
RewriteRule ^domains/appraisal /filter.php?module=2&filter=appraisal [R=301,NC,P]
RewriteRule ^domains/brokered /filter.php?module=2&filter=brokered [R=301,NC,P]
RewriteRule ^apps/all /filter.php?module=3&filter=all [R=301,NC,P]
RewriteRule ^apps/ios /filter.php?module=3&filter=ios [R=301,NC,P]
RewriteRule ^apps/android /filter.php?module=3&filter=android [R=301,NC,P]
RewriteRule ^apps/active /filter.php?module=3&filter=active [R=301,NC,P]
RewriteRule ^apps/ending /filter.php?module=3&filter=ending [R=301,NC,P]
RewriteRule ^apps/justsold /filter.php?module=3&filter=justsold [R=301,NC,P]
RewriteRule ^(websites|domains|apps|digitalGoods|sell)($|/) - [L]
RewriteRule ^item/(.*)$ ./show-digital.php?url=$1
RewriteRule ^([a-zA-Z0-9_-]+)$ show-detail.php?c=$1
RewriteCond %{HTTP_HOST} ^hiwebby\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.hiwebby\.com$
RewriteRule ^blog\/index\.php$ "http\:\/\/hiwebby\.com\/blog\/index\.php\/Support\/" [R=301,L]
答案 0 :(得分:0)
您必须添加[L]标志(最后) - 因此不会检查其他规则
RewriteRule ^websites/all /filter.php?module=1&filter=all [R=301,NC,P,L]
答案 1 :(得分:0)
你的重写规则似乎在很多方面都很可疑。在我的回答中,那里 对你来说也很少问题。使用重写规则配置服务器行为很棘手,任何错误配置都会导致网站出现严重问题。这就是完整查找是必要的原因。另外,您应该考虑阅读文档https://httpd.apache.org/docs/current/rewrite/flags.html#page-header
RewriteEngine on
RewriteBase /
没关系。
RewriteRule ^websites/all /filter.php?module=1&filter=all [R=301,NC,P]
RewriteRule ^websites/established /filter.php?module=1&filter=established [R=301,NC,P]
RewriteRule ^websites/starter /filter.php?module=1&filter=starter [R=301,NC,P]
RewriteRule ^websites/active /filter.php?module=1&filter=active [R=301,NC,P]
RewriteRule ^websites/ending /filter.php?module=1&filter=ending [R=301,NC,P]
RewriteRule ^websites/justsold /filter.php?module=1&filter=justsold [R=301,NC,P]
RewriteRule ^websites/dealflow /filter.php?module=1&filter=dealflow [R=301,NC,P]
但是在上面显示的代码中:
可能您没有使用代理或重定向。因此,您可以使用标记[NC,L]
。并且代替所有七行,您只需使用
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^websites/(.*)$ filter.php?module=1&filter=$1 [NC,L]
类似地
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^domains/(.*)$ filter.php?module=2&filter=$1 [NC,L]
和
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^apps/(.*)$ filter.php?module=3&filter=$1 [NC,L]
等等(如果有的话)。
RewriteRule ^(websites|domains|apps|digitalGoods|sell)($|/) - [L]
在上一行中,您将如何处理domain.com/websites
等请求。是否有名为websites
的目录?。
“ - ”语法表示不修改请求的URI。
RewriteRule ^item/(.*)$ ./show-digital.php?url=$1
上面的代码.
是否出于./show-digital.php?url=$1
的目的?并且没有提供标志。您可以像
RewriteRule ^item/(.*)$ show-digital.php?url=$1 [NC,L]
RewriteRule ^([a-zA-Z0-9_-]+)$ show-detail.php?c=$1 [NC,P]
此处,正确的标志也是[NC,L]
RewriteRule ^([a-zA-Z0-9_-]+)$ show-detail.php?c=$1 [NC,L]
RewriteCond %{HTTP_HOST} ^hiwebby\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.hiwebby\.com$
RewriteRule ^blog\/index\.php$ "http\:\/\/hiwebby\.com\/blog\/index\.php\/Support\/" [R=301,L]
在本节中,您可以解释您想要做什么。