homepage Welcome to WebmasterWorld Guest from 54.198.130.203
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
Quick help with RewriteRule
Rewrite static URL to dynamic script filepath
Jakotsu




msg:3593382
 8:23 pm on Mar 6, 2008 (gmt 0)

Hi, I'm needing to perform a RewriteCond for two type of URLs, such as:

example.com/mms/123456 -> convert to -> example.com/mypage.php?id=123456

The above could be made creating an extensionless mms file, but that method requires additional redirection internally and it's nasty, so I prefer to use the rewrite engine.

And another rule: (more important than the previous one)

example.com/abc123 -> example.com/user.php?id=abc123

I've searched on the forums but couldn't find a topic regarding these specific issues... any help will be greatly appreciated. Please ask if additional clarification is needed because my english might not be good enough, thanks!

-Andres.

 

gergoe




msg:3593444
 9:44 pm on Mar 6, 2008 (gmt 0)

This is the most simple use of mod_rewrite, did you tried looking into the mod_rewrite documentation [httpd.apache.org]?

Jakotsu




msg:3594061
 1:52 pm on Mar 7, 2008 (gmt 0)

Well I managed to rewrite localhost/test/index.php to localhost/argim/index.php with this:

RewriteRule ^test/([^/]+) /argim/$1 [L]

Problem here is with paths... the address bar remains with the base localhost/test/, causing all links and images to be broken, because /test/ is not the real path and the browser thinks it is.

If I add [R,L] at the end, I will be redirected to argim/index.php and links are OK, but this is not transparent to the user nor search engines because they'll see the real URL after the redirect, and this should not be allowed. I need to remain showing the original URL such as localhost/test/whatever and let the user thinks it's the real URL instead of a dummy redirect.

Any help is greatly appreciated... I succeeded in solving a problem and creating a new one, as usual.

[edited by: Jakotsu at 2:27 pm (utc) on Mar. 7, 2008]

jdMorgan




msg:3594100
 2:39 pm on Mar 7, 2008 (gmt 0)

> the address bar remains with the base localhost/test/, causing all links and images to be broken

You'll need to user server-relative links, such as <img src="/images/logo.gif"> or canonical links, such as <img src="http://www.example.com/images/logo.gif">, or you'll need to rewrite *all* requests from /test to /argim.

Remember, it is the client (browser or robot) which resolves page-relative or server-relative links, using the current directory-level in its address bar.

Jim

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved