如何重定向一个HTTP请求到一个静态文件的GET参数 [英] How to redirect a HTTP Request to a static File with the GET Parameter
问题描述
我有一个页面
example.com/u/_USERNAME_
和我想请求重定向到
example.com/u/profile.php?u=_USERNAME_
我试过的.htaccess(在/ u /文件夹),内容如下文件:
I've tried a .htaccess (in the /u/ folder) file with the following content:
RewriteEngine on
RewriteRule (.*)$ profile.php?u=$1
据请求重定向的可是的 $ _ GET ['U']
变量包含 profile.php
在哪里的问题?
我已经解决了这个问题:
文件 profile.php
是在 / U /
文件夹。所以规则重定向到自己的文件和GET参数迷路。
我已经把 profile.php
在rootfolder example.com /
和它的工作的!
I've solved the Problem:
The file profile.php
was in the /u/
Folder. So the Rule redirects to the own file and the GET Parameter get lost.
I've put the profile.php
in the rootfolder example.com/
and it work's!
推荐答案
在阿帕奇重写规则是规则前pressions,你写了一个整个字符串匹配。撰写,经过/匹配的东西规则U /从而使:
The apache rewrite rules are regular expressions, and the one you wrote matches a whole string. Write a rule that matches stuff after /u/ thus so:
RewriteRule ^u/([^/]*)$ /u/profile.php?u=$1 [L]
这篇关于如何重定向一个HTTP请求到一个静态文件的GET参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!