使用 HTACCESS 将斜杠后的文本转换为变量 [英] Turn text after slashes into variables with HTACCESS

查看:19
本文介绍了使用 HTACCESS 将斜杠后的文本转换为变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用 URL 传递 3 个变量,但使用斜杠.例如,我会使用这个 URL:

I need to pass 3 variables with a URL but using slashes. So for example I would use this URL:

http://www.example.com/variable1/variable2/variable3

我的 HTACCESS 中有这个,它允许传递第一个变量之后的文本,但我无法通过其他两个变量,即使我添加了 &$2

I have this in my HTACCESS which allows the text after the first variable to be passed but I can't get the other two to come through, even if I add &$2

<IfModule mod_rewrite.c>
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule /?([A-Za-z0-9_-]+)/?$ process.php?width=$1&height=$2 [QSA,L]

任何链接或帮助都会很棒

Any links or help would be great

推荐答案

您只在重写规则中捕获一个变量.

You are only capturing one variable in your rewrite rule.

你需要类似的东西:

RewriteRule ^([A-Za-z0-9_-]+)/([A-Za-z0-9_-]+)/([A-Za-z0-9_-]+)/?$ process.php?width=$1&height=$2&third=$3 [QSA,L]

或者,更短一点:

RewriteRule ^([w-]+)/([w-]+)/([w-]+)/?$ process.php?width=$1&height=$2&third=$3 [QSA,L]

(w 单词字符包括字母、数字和下划线)

(the w word character includes letters, digits and underscores)

我仅将结尾斜杠设为可选,因此此重写规则仅在恰好有 3 个变量时才起作用.

I have made only the ending slash optional so this rewrite rule would only do something if there are exactly 3 variables.

这篇关于使用 HTACCESS 将斜杠后的文本转换为变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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