PHP .htaccess mod_rewrite [英] PHP .htaccess mod_rewrite

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

问题描述

所以我想使用mod_rewrite进行转换:

So I want to use mod_rewrite to transform:

random_name.com/main.php?user=$user

进入

random_name.com/$user

($ user是一个添加到url上的php变量,因此它可以是任何名称,例如andy或rebecca,诸如此类)

(the $user is a php variable added onto the url, so it can be any name such as andy or rebecca, names like that)

我的.htaccess代码是:

and my code for the .htaccess is:

RewriteEngine on
RewriteRule ^/([A-Za-z0-9-]+)/?$ main.php?id=$1 [NC,L] 

但是由于某种原因,这似乎不起作用.我已经阅读了这些教程,但它们确实很复杂,似乎可以解决问题,但事实并非如此.如果有任何使用mod_rewrite的经验的人给我一些指导,我将不胜感激.

But this doesn't seem to work for some reason. I've read up on the tutorials but they're really complicated and it seems like this would do the trick, but it doesn't. I'll appreciate it if anyone who has experience with mod_rewrite would give me a few pointers.

推荐答案

尝试一下:

RewriteEngine on
RewriteRule ^([A-Za-z0-9-]+)$ main.php?user=$1 [NC,L] 

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

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