使用apache重写时如何隐藏URL更改?

时间:2021-08-06 11:19:02

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!

使用apache重写时如何隐藏URL更改?我已经在这个问题上搜索了几个小时,并决定来这里找出答案。所以任何帮助/线索将不胜感激!

Right now I am using:

现在我正在使用:

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

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时,它的工作原理。但是,它将浏览器网址更改为http://domain.com/page.cfm?pagevar=abc123,

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

我希望它执行相同的操作,但显示http://domain.com/Page/abc123作为网址。

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

拜托,对此有任何见解将非常感谢!再次感谢。

2 个解决方案

#1


7  

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

第一条规则会将丑陋的URL重定向到漂亮的URL格式。

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

第二条规则将在内部重定向它,因为用户将看不到丑陋的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]

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.

上述规则将用于.htaccess文件,并假设page.cfm与.htaccess文件一起位于域文件夹的根目录下。

Like your examples proposes.

像你提出的例子一样。

#2


0  

You need to get rid of the http://domain.com part of the rule's target. When you have that, it implicity redirects the browser instead of internally rewriting:

您需要摆脱规则目标的http://domain.com部分。如果你有这个,它隐含的重定向浏览器而不是内部重写:

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

#1


7  

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

第一条规则会将丑陋的URL重定向到漂亮的URL格式。

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

第二条规则将在内部重定向它,因为用户将看不到丑陋的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]

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.

上述规则将用于.htaccess文件,并假设page.cfm与.htaccess文件一起位于域文件夹的根目录下。

Like your examples proposes.

像你提出的例子一样。

#2


0  

You need to get rid of the http://domain.com part of the rule's target. When you have that, it implicity redirects the browser instead of internally rewriting:

您需要摆脱规则目标的http://domain.com部分。如果你有这个,它隐含的重定向浏览器而不是内部重写:

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