用户ID动态页面的.htaccess [英] User id dynamic pages .htaccess

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

问题描述

我有这个网址
www.mydomain.com/profile.php?id=524170354d5a6
我想将其转换为一个友好的URL是这样的:
www.mydomain.com/profile/524170354d5a6
我已经尝试过用.htacces文件,但它不工作,我的.htaccess坐落在我的文件夹proyect(WWW /项目 - > htacces)这个位置呢?或者它是在(WWW /的.htaccess) 我的.htaccess包含code:

I have this url
www.mydomain.com/profile.php?id=524170354d5a6
and I want to convert it to a friendly url like this :
www.mydomain.com/profile/524170354d5a6
I already tried with .htacces file but it doesn't work, my .htaccess is located inside my folder proyect (www/project->.htacces) Does this well located? or it has to be in (www/.htaccess) my .htaccess contain the code:

RewriteEngine On
RewriteRule ^profile/(\d+)*$ /profile.php?id=$1

我看到了网上的几个例子,但没有工作,也有可能是因为我的ID包含数字和字母?还是我的正则表达式是错误的?

I saw several examples in Internet but none works, it could also be because my id contains numbers and letters? or my regex is wrong?

推荐答案

要做出花哨的网址,你需要一个规则将在丑陋的网址进入花哨的网址。这是通过所谓的外部重定向的完成。你需要的其他规则将在花哨的网址进入丑陋的网址内部,从而使服务器知道该怎么做。这将创建一个永久的循环,如果你不这样做prevent是通过 END 标记(可从Apache的2.3.9及以上)或者 THE_REQUEST 招。

To make fancy url's, you'll need a rule to turn the 'ugly' url into the 'fancy' url. This is done via a so-called external redirect. You'll need an other rule to turn the 'fancy' url into the 'ugly' url internally, so that the server knows what to do. This will create a perpetual loop if you do not prevent that via the END flag (available from Apache 2.3.9 and up) or the THE_REQUEST trick.

#Rewrite fancy url to ugly url internally and stop rewriting completely
#RewriteRule ^profile/(.*)$ profile.php?id=$1 [END]

#Internal rewrite pre-2.3.9
RewriteCond %{THE_REQUEST} ^GET\ /profile/(.*)\ .*$
RewriteRule ^ profile.php?id=%1 [L]

#Redirect the ugly url to the fancy url, so that the user will always see the fancy url in the address bar
RewriteCond %{QUERY_STRING} ^id=(.*)$
RewriteRule ^profile\.php$ profile/%1 [R,L]

(我不能在这台计算机上测试这一点)

(I can't test this on this computer)

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

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