在不使用htaccess重定向的情况下更改浏览器中的URL [英] Change URL in browser without redirection with htaccess

查看:86
本文介绍了在不使用htaccess重定向的情况下更改浏览器中的URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我到处寻找合适的解决方案/方法,但似乎找不到对我有用的任何东西. 我什至问过朋友,他们帮助了他们,但没有成功.

I've looked everywhere to find the proper solution/method but I can't seem to find anything that works for me. I even asked friends and they helped but none prevailed.

我想做的是,更改浏览器中显示的URL,但仅此而已. (不编辑,重新加载页面). 我想这样做是为了使我的UCP在浏览某些页面/文件时看起来更加整洁.

What i'm trying to do is, changing the URL displayed in the browser but only that. (No rediraction, page re-loading). I want to do this to make my UCP just cleaner looking when going through certain pages/files.

我要实现什么目标? 这是个人资料上的示例,URL为:

What am I trying to achieve? Heres an example on a profile, the URL would be:

mysite.com/ucp/profile.php?player=Heartfire

但是,我希望它看起来像

However, I want it to look like

mysite.com/ucp/profile/heartfire

还有别的!我只想在.PHP

Or something else! I just want to get rid of the parameters AFTER the .PHP

我已经尝试过在Google和该网站上找到的各种示例,但似乎都没有用,有人可以指导我实现结果.

I've tried various examples found with google and this website but none seems to work, could somebody please guide me along the way to achieve the result.

到目前为止我尝试了什么? 以下是我之前尝试过的一些示例:

what have I tried so far? Here are a few examples of what I tried before:

RewriteRule ^profile/([0-9]+)/?$    /ucp/profile.php?player=$1
RewriteRule profile.php?player=$1 profile.php [NC,L]
RewriteRule ^profile$ profile.php?player=$1

那我在做什么错了呢?

推荐答案

在网站根目录下的.htaccess文件中放置以下内容:

Put the following in .htaccess file inside website's root directory:

RewriteEngine On

RewriteCond %{THE_REQUEST} ^GET\ /ucp/profile\.php?([^=]+)=(\S+) [NC]
RewriteRule ^ucp/profile\.php$ /ucp/%1/%2? [R=301,L,NC]

# Now, deal with internal rewrites (which will not cause redirection):
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ucp/([^/]+)/([^/]+)/?$ /ucp/profile.php?$1=$2 [NC,L]

这篇关于在不使用htaccess重定向的情况下更改浏览器中的URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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