奇怪的URL重写规则的.htaccess问题需要交代

编程入门 行业动态 更新时间:2024-10-13 00:34:47
本文介绍了奇怪的URL重写规则的.htaccess问题需要交代的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个 book.php中?ID = 23 和使用htaccess的,使它们书籍/ ID /标题 我想这

重写规则^书/([0-9] +)/([^ /] +)/ $ book.php中?ID = $ 1 [NC,L,QSA]

但没有奏效,它转发到 books.php ,但没有 $ _ REQUEST 数据  事实证明,这是因为该URL引用是相同的名称作为PHP文件我打电话的帮助来自社会来解决这个工作

重写规则^书/([0-9] +)/([^ /] +)/ $ book.php中?ID = $ 1 [NC,L,QSA]

这是我目前工作的.htaccess:

RewriteEngine叙述上 重写规则^ kitap /([0-9] +)/([^ /] +)/ $ book.php中?ID = $ 1 [NC,L,QSA] 重写规则^ yyin中/([0-9] +)/([^ /] +)/ $ yayin.php?ID = $ 1 [NC,L,QSA] 重写规则^幻灯/([0-9] +)/([^ /] +)/ $ project.php?ID = $ 1 [NC,L,QSA]

彼得:

  

我见过的每一个在线教程使用像^产品和示例   product.php,或^类category.php所以我不知道为什么会这样   应该。也许别人可以阐明这一些轻?

解决方案

我开始后,我们对你原来的问题小议这个搞乱,我开始认为这取决于服务器的配置,以及是否将运行扩展名的脚本。

我的开发服务器,例如,将运行扩展名的脚本,即输入/ XYZ将显示xyz.php

的重写规则

重写规则^类/([0-9] +)/([^ /] +)/ $ category.php?ID = $ 1 [NC,L,QSA]

不工作,但是

重写规则^类别/([0-9] +)/([^ /] +)/ $ category.php?ID = $ 1 [NC,L,QSA]

做的工作。

在我的托管服务器,它不支持extentionless脚本,www.mydomain/xyz会给我一个404错误,但是:

重写规则^类/([0-9] +)/([^ /] +)/ $ category.php?ID = $ 1 [NC,L,QSA]

按预期工作。

我只能假设,当服务器支持扩展名的脚本,然后重写规则是,如果别名是相同的脚本名称忽略。

I have URLs like book.php?id=23 and using htaccess to make them book/id/title I tried this

RewriteRule ^book/([0-9]+)/([^/]+)/?$ book.php?id=$1 [NC,L,QSA]

but it didn't work, it was forwarding to books.php but no $_REQUEST data it turned out it was because the url reference was the same as the name as the php file I was calling with help from the community to work around this worked

RewriteRule ^books/([0-9]+)/([^/]+)/?$ book.php?id=$1 [NC,L,QSA]

this is my current working .htaccess:

RewriteEngine On RewriteRule ^kitap/([0-9]+)/([^/]+)/?$ book.php?id=$1 [NC,L,QSA] RewriteRule ^yyin/([0-9]+)/([^/]+)/?$ yayin.php?id=$1 [NC,L,QSA] RewriteRule ^proje/([0-9]+)/([^/]+)/?$ project.php?id=$1 [NC,L,QSA]

PeteR:

every online tutorial I've ever seen uses examples like ^product and product.php, or ^category and category.php so I don't know why this should be. Maybe someone else can shed some light on this?

解决方案

I started messing with this after our small discussion on your original question and I'm starting to think it depends on the server configuration and whether or not it will run extensionless scripts.

My dev server, for example, will run extensionless scripts, i.e. typing /xyz will display xyz.php

A rewrite rule of

RewriteRule ^category/([0-9]+)/([^/]+)/?$ category.php?id=$1 [NC,L,QSA]

does not work, however

RewriteRule ^categories/([0-9]+)/([^/]+)/?$ category.php?id=$1 [NC,L,QSA]

does work.

On my hosting server, which does not support extentionless scripts, www.mydomain/xyz will give me a 404 error, but:

RewriteRule ^category/([0-9]+)/([^/]+)/?$ category.php?id=$1 [NC,L,QSA]

works as expected.

I can only assume that when the server supports extensionless scripts then the rewrite rule is ignored if the alias is identical to the script name.

更多推荐

奇怪的URL重写规则的.htaccess问题需要交代

本文发布于:2023-11-02 00:29:39,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1550850.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:重写   问题需要   交代   奇怪   规则

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!