需要调整 htaccess

发布于 2024-12-10 21:32:50 字数 1283 浏览 0 评论 0原文

我有这个 htaccess ,效果很好。我还想做一件事。我严格控制网站中的网址,效果很好。我想阻止人们向该网站添加任意请求。

我正在使用友好的网址。我的网址是这样工作的:

http://www.mysite.net/pagename

因此,如果您尝试放入不存在的页面,则会收到 404 错误。这一切都很好。但我想进一步限制事情。

目前,如果你放入index.php,它也可以工作,你会发现

http://www.mysite.net/index.php

我想限制这种行为,因为人们可以添加,搜索引擎可以索引向url添加任意请求

http://www.mysite.net/index.php?test=somthing

,这样不会抛出404,而是返回主页页面索引.php。我希望这些类型的 url 能够抛出 404。

我的 htaccess 位于下面,我可以做些什么来修复它。

RewriteEngine On


#RewriteRule ^gallery(/((([a-zA-Z0-9-]+)(/(\d+))?)/?)?)?$ index.php?page=77&groupId=$4&showpage=$6 [NC,QSA,L]

RewriteRule ^gallery/([a-zA-Z0-9-]+)/(\d+)/?$ index.php?page=77&groupId=$1&showpage=$2 [NC,QSA,L]
RewriteRule ^gallery/([a-zA-Z0-9-]+)/?$ index.php?page=77&groupId=$1 [NC,QSA,L]
RewriteRule ^gallery/?$ index.php?page=77 [NC,QSA,L]

RewriteRule ^video/(\d+)/([a-zA-Z0-9-]+)/?$ index.php?page=60&showpage=$1&v=$2 [NC,QSA,L]
RewriteRule ^video/(\d+)/?$ index.php?page=60&showpage=$1 [NC,QSA,L]
RewriteRule ^video/?$ index.php?page=60 [NC,QSA,L]

RewriteCond %{REQUEST_FILENAME} !-f [NC]
#RewriteCond %{REQUEST_FILENAME} !-d [NC]
RewriteRule ^(.+)$ index.php?page=$1 [NC,QSA,L]

I have this htaccess which works great. I would like to do one more thing. I have the urls in the site tightly controlled it works fine. I would like to prevent people from adding arbitrary requests to the site.

I am using friendly urls. My urls work like this:

http://www.mysite.net/pagename

So if you try to put in a non existent page you get a 404 error. This all works fine. But I would like to restrict things further.

Currently if you put in index.php it works too and you get brought to

http://www.mysite.net/index.php

I want to restrict this behaviour as people can add and search engines can index add arbitrary requests to the url like

http://www.mysite.net/index.php?test=somthing

and this does not throw a 404 but goes to the home page index.php. I would like these types of urls to throw 404's.

My htaccess is below is there anything I can do to fix it there.

RewriteEngine On


#RewriteRule ^gallery(/((([a-zA-Z0-9-]+)(/(\d+))?)/?)?)?$ index.php?page=77&groupId=$4&showpage=$6 [NC,QSA,L]

RewriteRule ^gallery/([a-zA-Z0-9-]+)/(\d+)/?$ index.php?page=77&groupId=$1&showpage=$2 [NC,QSA,L]
RewriteRule ^gallery/([a-zA-Z0-9-]+)/?$ index.php?page=77&groupId=$1 [NC,QSA,L]
RewriteRule ^gallery/?$ index.php?page=77 [NC,QSA,L]

RewriteRule ^video/(\d+)/([a-zA-Z0-9-]+)/?$ index.php?page=60&showpage=$1&v=$2 [NC,QSA,L]
RewriteRule ^video/(\d+)/?$ index.php?page=60&showpage=$1 [NC,QSA,L]
RewriteRule ^video/?$ index.php?page=60 [NC,QSA,L]

RewriteCond %{REQUEST_FILENAME} !-f [NC]
#RewriteCond %{REQUEST_FILENAME} !-d [NC]
RewriteRule ^(.+)$ index.php?page=$1 [NC,QSA,L]

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文