mod_rewrite (invisible rewrite)

dongbamage

New Member
Messages
17
Reaction score
0
Points
0
Hi!

I'm attempting to make my urls prettier by using mod_rewrite.

So I've setup my .htaccess with the following:
Code:
RewriteEngine on
Rewritebase /

RewriteRule ^articles/([^/]+)/?$ http://myurl.pcriot.com/myfolder/subfolder/index.php?url=$1 [L]
in the address bar I can then enter:

http://myurl.pcriot.com/myfolder/subfolder/articles/contact/

the redirect works correctly, however the address bar shows:

http://myurl.pcriot.com/myfolder/subfolder/index.php?url=contacts

How can I make the address bar display my pretty link whilst still rewriting (ie an invisible rewrite)

I've searched the forums and googled like a madman, but I can't seem to find a solution. Can anybody please help?
 

descalzo

Grim Squeaker
Community Support
Messages
9,373
Reaction score
326
Points
83
Code:
RewriteEngine on
Rewritebase /

RewriteRule ^articles/([^/]+)/?$ myfolder/subfolder/index.php?url=$1 [L]

If you have the http://myurl.com in the RewriteRule, you effectively get a redirect (which will show the new URL) instead of a rewrite (which will show the pretty url)
 

descalzo

Grim Squeaker
Community Support
Messages
9,373
Reaction score
326
Points
83
Code:
RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_URI} !=/favicon.ico
  RewriteRule ^(.+)$ myfolder/subfolder/index.php?url=$1 [L]

If the request does not match a file or directory and is not for the favicon, it sticks it at the end for your index.php to handle. You have to add logic to make sure what to do with the info (ie, if it is a bad request, you serve up a "Resource not located" page).
 
Last edited:

dongbamage

New Member
Messages
17
Reaction score
0
Points
0
Figured it out:

RewriteCond %{REQUEST_URI} !portfolio
RewriteRule ^(.+)$ myfolder/subfolder/index.php?linkdata=$1

RewriteCond %{REQUEST_URI} portfolio
RewriteRule ^(portfolio)-([0-9]+)$ myfolder/subfolder/index.php?linkdata=$1&id=$2

Thanks for helping!
 
Top