PHP的.htaccess重写 [英] .htaccess php Rewrite

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

问题描述

我有一个问题rewritting /认证/ view_profile?用户=(用户名),以myurl.com/profil/(username~~V)

I have a problem rewritting /authentication/view_profile?user=(username) to myurl.com/profil/(username)

现在我的.htaccess文件是:

Right now my .htaccess file is:

RewriteEngine On
#Rewrite /view.php?vis=id to /opslag/vis/id
#RewriteRule ^opslag/vis/(\d+)$ /opslag/view.php?vis=$1 [NC,QSA,L]

#Rewrite authentication/view_profile.php?user=* to profil/*
RewriteRule ^profil/(\d+)$ /authentication/view_profile.php?user=$1 [NC,QSA,L]

#Remove index.php
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*index\.php\ HTTP/
RewriteRule ^(.*)index\.php$ /$1 [R=301,L]

#Remove /page/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/\.]+)/?$ index.php?page=$1 [L]

我已经使用规则重写一个又一个,这是#Rewrite view.php?可见= id来/ opslag /可见/ ID

I'm already using a rule to rewrite another one, which is the "#Rewrite view.php?vis=id to /opslag/vis/id

现在我的网址是这样的:

Right now my URL's look like this:

<a href='/profil/$_SESSION[username]'>Vis profil</a>

我希望你要帮帮我。

I hope you wanna help me.

如果你需要一些详细信息,请告诉我..:O)

If you need some details please just tell me.. :o)

推荐答案

使用这个来代替:

RewriteRule ^profil/([^/]+)$ /authentication/view_profile.php?user=$1 [NC,QSA,L]

您的规则只能接受用户名,如果他们包含数字仅(\ d +)。这其中([^ /] +)将接受任何字符(除 / ,这是一个文件夹分隔符)。

Your rule can only accept usernames if they consist of digits only (\d+). This one ([^/]+) will accept any characters (except /, which is a folder delimiter).

P.S。 考虑阅读此介绍到正规EX pressions,如果你mod_rewrite的计划用定期的.htaccess和URL重写规则。

P.S. Consider reading this Introduction to regular expressions and mod_rewrite if you plan to use .htaccess and URL rewrite rules on regular basis.

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

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