奇怪的URL重写规则的.htaccess问题需要交代 [英] Strange URL RewriteRule .htaccess Issue needs explaination

查看:115
本文介绍了奇怪的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.com/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.com/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问题需要交代的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆