Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/fsharp/3.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文件的重定向问题_.htaccess_Mod Rewrite - Fatal编程技术网

PHP中.htaccess文件的重定向问题

PHP中.htaccess文件的重定向问题,.htaccess,mod-rewrite,.htaccess,Mod Rewrite,我有一个类似的网站。我正在使用.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

我有一个类似的网站。我正在使用
.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]

您必须添加[L]标志(最后一个),以便不检查其他规则

RewriteRule ^websites/all /filter.php?module=1&filter=all [R=301,NC,P,L]

您的重写规则在许多行中似乎是可疑的。在我的回答中,有 还有几个问题要问你。使用重写规则配置服务器行为非常棘手。任何错误配置都会导致网站出现严重问题。这就是为什么需要进行完整的查找。此外,你也应该考虑阅读文件

那很好


但在上面显示的代码中:
可能您没有使用代理或重定向。因此,您可以使用flag
[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]

依此类推(如果有的话)


在上面的行中,您将如何处理像
domain.com/websites
这样的请求。是否有名为
网站
的目录

“-”语法意味着请求的URI未被修改


在上面的代码中,
中是否有任何用途的
/show digital.php?url=$1
?而且也没有提供国旗。你可以像这样修改它

RewriteRule ^item/(.*)$ show-digital.php?url=$1 [NC,L]

这里正确的标志应该是
[NC,L]

RewriteRule ^([a-zA-Z0-9_-]+)$ show-detail.php?c=$1 [NC,L]


在本节中,您能解释一下您想做什么吗。

这两条规则在同一个.htaccess文件中吗?按哪个顺序?能否显示.htaccess文件的更多相关部分?您尝试访问的url是什么?在
.htaccess
file@GolezTrol,是,两个规则都在同一个htaccess文件中。@lkdhruw,ys,.htaccess文件有更多规则。RewriteRule^websites/all/(.*)$/filter.php?module=1&filter=all[R=301,NC,P,L]RewriteRule^websites/builded/(.*)$/filter.php?module=1&filter=starter[R=301,NC,P,L]RewriteRule^websites/active/filter.php?module=1&filter=active=active[R=301,NC,P,L]重写规则^websites/ending/filter.php?模块=1&filter=ending[R=301,NC,P,L]重写规则^([a-zA-Z0-9_-]+)$show detail.php?c=$1模块2和模块2相同3@Ankit如果你在你的问题中加上这几行话会更好。对不起,先生,不能成功。。。。真正的url是yoursitename.com/filter.php?module=1&filter=所有url都应该显示为yoursitename.com/websites/all where module=1(网站)和filter=all1)确保您没有弄乱htaccess中的RewriteBase 2)在测试301重定向时使用命令行工具,而不是浏览器,浏览器经常会非常积极地缓存301重定向(这些重定向是永久性的)——我建议通过curl或httpiet进行测试,非常感谢。如您所问,有一些文件夹包含网站、域和应用程序的名称。但是filter.php、show-detail.php和show-digital.php文件位于根目录中。您提供的代码运行良好。但有一个小问题。域名和应用程序的重定向工作正常,但网站重定向并没有将我带到所需页面。如果我使用domain.com/website,那么它可以工作,但不能与domain.com/website一起工作如果我想访问[link](domain.com/websites/index.php),它需要我去filter.php页面,但在地址栏中它显示了url domain.com/websites/@Ankit,所以
domain.com/websites/index.php
存在,您可以在重写规则之前设置重写条件。我已经相应地更新了。谢谢您的快速回复。现在问题已经100%解决了。再次感谢。我们可以亲自通过邮件联系吗?当然可以通过lkdhruw@live.com
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]
RewriteRule ^item/(.*)$ ./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]
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]