.htaccess - Redirect loop while looking for uri that does NOT contain specific string
问题描述
I have an site lets say https://example.com/ and I would like to redirect every url that doesn't begins with /something
to https://example.com/something/
I'm using Apache 2.4.29 (hosting) and my .htaccess looks like this.
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/something(.*)$ [NC]
RewriteRule ^(.*)$ /something/ [R=302,NC,L]
My problem is that when I'm on homepage (/
) or any other page I'm redirected to /something/
which is correct but when I'm on /something/
I'm still beeing redirected to /something/
and it loops until ERR_TOO_MANY_REDIRECTS error shows up.
Here is a link to htaccess tester which shows that this should work and should not redirect me to /something/
when I'm already here but it is not the case on my hosting.
解决方案
With your shown attempts, please try following set of rules. Please place them on top of htaccess rules file in case you already have existing rules.
Please make sure to clear your browser cache before testing your URLs.
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/?$
RewriteCond %{THE_REQUEST} !something [NC]
RewriteRule ^ /something? [R=302,NC,L]
推荐阅读
- angularjs - 如何使用 angularjs 中的绑定从父级调用子函数
- php - 如何使用不同/多个@param
- docker - iptable 规则阻止我连接到在 localhost 上运行的 docker 代理
- influxdb - InfluxDB 连续查询:保留标签
- javascript - 是否可以在没有 jQuery 的情况下切换 div?
- python - Python从其他文件夹(在同一个项目中)导入文件?
- python - 根据 QCombobox 中选择的选项替换复选框
- php - 重新分配信封后无法检索选项卡数据
- c++ - 互斥锁在 mingw 中停止程序,但在 linux 上没有
- ios - 从真实 iOS 设备获取剪贴板