Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to hide the URL change when using apache rewrite?

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!

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,

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

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

like image 679
cEMa Avatar asked Sep 06 '13 15:09

cEMa


1 Answers

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

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]

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.

Like your examples proposes.

like image 187
Prix Avatar answered Sep 19 '22 07:09

Prix