如何使用Apache重写时隐藏URL的变化? [英] How to hide the URL change when using apache rewrite?

查看:375
本文介绍了如何使用Apache重写时隐藏URL的变化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何隐藏URL改变使用Apache重写的时候?我已经搜索了几个小时就这个问题,并已决定到这里来找出答案。所以任何帮助/线索,将大大AP preciated!

How do I hide the URL change when using an apache rewrite? I have searched for hours on this issue and have decided to come here to find out the answer. So any help/clues would be greatly appreciated!

现在,我使用的:

RewriteRule ^/Page/(.*)$ http://domain.com/page.cfm?pagevar=$1 [NC,L]

这问题是,当你去浏览到 http://domain.com/Page/abc123 它的工作原理。但是,它改变了浏览器的URL http://domain.com/page.cfm?pagevar=abc123

The problem with that is, when you go navigate to http://domain.com/Page/abc123 it works. BUT, it changes the browser url to http://domain.com/page.cfm?pagevar=abc123,

我希望它执行相同的动作,但表现 http://domain.com/Page/abc123作为URL。

I want it to perform that same action, but show http://domain.com/Page/abc123 as the url.

请,在这个任何见解将是非常美联社preciated! 再次感谢。

Please, any insight on this would be very appreciated! Thanks again.

推荐答案

第一条规则将重定向你的丑陋的URL到pretty的URL格式。

First rule will redirect your ugly URL to the pretty URL format.

第二条规则将在内部重定向回用户将无法看到丑陋的URL。

Second rule will internally redirect it back for the user will not see the ugly URL.

Options +FollowSymLinks -MultiViews

RewriteEngine On
RewriteBase /

# Redirect /page.cfm?pagevar=abc123 to /Page/abc123
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+page\.cfm\?pagevar=([^&\s]+) [NC]
RewriteRule ^ /Page/%1? [R=301,L]

# Internally forward /Page/abc123 to /page.cfm?pagevar=abc123
RewriteRule ^Page/(.*)/?$ /page.cfm?pagevar=$1 [QSA,NC,L]

以上规则是要在的.htaccess 文件中使用,并假定 page.cfm 是根您正在访问的文件夹随的.htaccess 文件。

The above rules are to be used on .htaccess files and assumes page.cfm is on the root of your domain folder along with the .htaccess file.

就像你的例子提出。

这篇关于如何使用Apache重写时隐藏URL的变化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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