将尾部斜杠添加到 Mod_rewrite 并在虚拟目录中重定向非尾部斜杠
有时会发生这样的情况,我在 htaccess 文件中创建了我所说的一团糟。我遇到了几个问题,我知道我有时会在内部循环,而且无论如何我并不擅长于此。我浏览了几十个这样的问题并尝试了很多解决方案。最终的结果是,我试图将多个单独的解决方案拼凑在一起来解决一个多部分问题,但我弄得一团糟。这几天来这就是我的使命。我被困住了。坏的。
- 我希望 mydomain.com/handmade-jewelry 转到 mydomain/handmade-jewelry/ (注意斜杠)
- 然后我也将 .com/handmade-jewelry/some-piece 转到 Jewelry-details.php?id=some-piece。这可行,但它还需要一个尾部斜杠。
- 当我尝试在“/some-piece/”上显示尾部斜杠时,它会重定向并命中未找到的文件。
相信我。我知道我的逻辑肯定存在明显的缺陷,而且从周六开始我就拒绝问这个问题。我知道这是非常常见的问题。如果我没有被困住,我不会问。
( rewrite all www and non-www requests to https:// ...works fine)
RewriteCond %{HTTP_HOST} ^domain\.com$ [NC]
RewriteRule ^(.*)$ https://www.domain.com/$1 [R=301,L]
RewriteCond %{HTTPS} !=on
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R,L]
RewriteCond %{SERVER_PORT} ^80$
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R,L]
(redirecting to the page with all the jewelry)
RewriteRule ^handmade-jewelry/$ jewelry-inventory-page.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
(following was a failed attempt.)
# RewriteCond %{REQUEST_URI} !rock-jewelry/(.*)/$
(following works with no trailing slash, which is needed)
RewriteRule ^handmade-jewelry/(.*)$ jewelry-details.php?s=$1 [L]
(if I turn this on, it goes to a 404 looking for "handmade-jewelry/this-piece/index.php?s=thispiece/etc...")
# RewriteRule ^handmade-jewelry/(.*)?/$ jewelry-details.php?s=$1 [L]
再次抱歉。我知道对于很多人来说,这种问题是多余的。
AS sometimes happens, I have created what I would say is a hot mess in my htaccess file. I've got several problems, I know I'm internally looping on occasion, and I'm not great at this anyways. I've looked through dozens upon dozens of SO questions and tried tons of solutions. The end result is that I'm trying to piece together more than one separate solution to a multi-part problem and I've made a real mess. This is exclusively been my mission for days. I'm stuck. Bad.
- I want mydomain.com/handmade-jewelry to go to mydomain/handmade-jewelry/ (note slash)
- Then I also have .com/handmade-jewelry/some-piece going to jewelry-details.php?id=some-piece. That works, but it also needs a trailing slash.
- When I try to show a trailing slash on "/some-piece/", it redirects out and hits a file not found.
Trust me. I know there's got to be glaring flaws in my logic here, and I resisted asking this question since Saturday. I know this is super-oft asked. I wouldn't be asking if I wasn't dead stuck.
( rewrite all www and non-www requests to https:// ...works fine)
RewriteCond %{HTTP_HOST} ^domain\.com$ [NC]
RewriteRule ^(.*)$ https://www.domain.com/$1 [R=301,L]
RewriteCond %{HTTPS} !=on
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R,L]
RewriteCond %{SERVER_PORT} ^80$
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R,L]
(redirecting to the page with all the jewelry)
RewriteRule ^handmade-jewelry/$ jewelry-inventory-page.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
(following was a failed attempt.)
# RewriteCond %{REQUEST_URI} !rock-jewelry/(.*)/$
(following works with no trailing slash, which is needed)
RewriteRule ^handmade-jewelry/(.*)$ jewelry-details.php?s=$1 [L]
(if I turn this on, it goes to a 404 looking for "handmade-jewelry/this-piece/index.php?s=thispiece/etc...")
# RewriteRule ^handmade-jewelry/(.*)?/$ jewelry-details.php?s=$1 [L]
Sorry again. I know for a lot of you, this kind of question gets redundant.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试将以下内容添加到站点根目录中的 htaccess 文件中
Try adding the following to your htaccess file in the root directory of your site