Forum Moderators: phranque

Message Too Old, No Replies

How to mask an URL with .htaccess

I tried 4 different RewriteRules

         

guarriman

8:49 am on Sep 10, 2007 (gmt 0)

10+ Year Member



Hi.

I've been browsing some threads at WebmasterWorld, but didn't find the right rule to perform what I'm trying to do.

I want to make [mysite.com...] --> [mysite.com...]
but not redirecting but masking the URL (the first URL must be shown and not the second one).

My .httaccess:
--------------------------
RewriteEngine On
RewriteBase /
DirectoryIndex index.php index.html
RewriteRule ^post/(.*).htm post.php?id=$1 [R=301,L]
---------------------------

I also tried with:
RewriteRule ^post/(.*).htm post.php?id=$1 **whithout R,L**
I got this URL: [mysite.com...]

I also tried with
RewriteRule ^post/(.*).htm post.php?id=$1 [L]
I got this URL: [mysite.com...]

I also tried with
RewriteRule ^post/(.*).htm [mysite.com...] [L]
I got this URL: [mysite.com...]

Any suggestion?

phranque

11:14 am on Sep 10, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



I also tried with
RewriteRule ^post/(.*).htm post.php?id=$1 [L]
I got this URL: [mysite.com...]

this looks like the correct rule for an internal rewrite.
isn't this what you wanted?

other than that, the ".*" in your regexp is considered "ambiguous, greedy and promiscuous", so it might be better to use something more efficient like "[^.]*"
or perhaps "[0-9]*" if appropriate.

jdMorgan

12:37 pm on Sep 10, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



And escape the literal period in the pattern and end-anchor it as well.

RewriteRule ^post/([^.]+)\.htm$ post.php?id=$1 [L]

Also, completely flush your browser cache before testing any new code changes on your server in order to avoid seeing a stale, locally-cached response.

Jim

g1smd

6:54 pm on Sep 10, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



What do you get when you try to access this URL:

http://www.mysite.com/post/004.htm

phranque

1:21 am on Sep 11, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



And escape the literal period in the pattern

oops - missed that one!