Welcome to WebmasterWorld Guest from

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Quick help with RewriteRule

Rewrite static URL to dynamic script filepath



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

10+ Year Member

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!



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

10+ Year Member

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


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

10+ Year Member

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]


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

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

> 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.



Featured Threads

Hot Threads This Week

Hot Threads This Month