htaccess mod_rewrite子文件夹中的URL [英] htaccess mod_rewrite URL within subfolder

查看:56
本文介绍了htaccess mod_rewrite子文件夹中的URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题似乎在StackOverflow上没有得到回答,所以去了:

My question seems to be unanswered on StackOverflow, so here goes:

我想使用根文件夹中的 htaccess 文件重写以下URL.

I want to rewrite the following URL using an htaccess file which is in the root folder.

要重写的URL是这样的:

The URL to rewrite is this:

http://www.domain.com/subfolder/item/12345

对此:

http://www.domain.com/subfolder/item.php?id=12345

但是我似乎无能为力.如果使用以下方法,我可以成功重写item.php URL:

However nothing I seem to do works. I can successfully rewrite the item.php URL if it is in the root folder using this:

RewriteRule ^item/(.*)$ item.php?id=$1 [NC,L]

...但是如果item.php文件位于子文件夹中,则不会!

... but not if the item.php file is in a subfolder!

推荐答案

您可以在子文件夹中使用以下.htaccess:

You can use following .htaccess in your subfolder:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /subfolder

RewriteRule ^item/(.*)$ item.php?id=$1 [NC,L,QSA]

您重写的URL将变为:http://domain.com/subfolder/item/123

Your rewritten URL would become: http://domain.com/subfolder/item/123

这篇关于htaccess mod_rewrite子文件夹中的URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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