URL重写帮助 [英] URL Rewriting Help

查看:132
本文介绍了URL重写帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想学习正则表达式和放大器; URL重写PHP中。如何创建一个.htaccess文件将改写(不定向)的任何网址的index.php?Q = {URL}

I'm trying to learn Regex & URL Rewriting in PHP. How can I create an .htaccess file which will rewrite (not redirect) any url to index.php?q={url}?

例如:

http://www.example.com/baloon

http://www.example.com/index.php?q=baloon

我想:

RewriteEngine On
RewriteRule ^$ index.php?q=$1 [R]

...但它不工作。我究竟做错了什么?

...but it is not working. What am I doing wrong?

感谢。

推荐答案

重写任何URL的index.php Q = $ 1将会导致内部服务器错误,因为它会创建一个无限循环?;而不是做这样的事情:

Rewriting ANY url to index.php?q=$1 would result in internal server error as it'd create an endless loop; instead do something like this:

RewriteEngine on
RewriteCond %{REQUEST_URI} !^/index\.php
RewriteRule ^(.*)$ index.php?q=$1 [L]

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

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