homepage Welcome to WebmasterWorld Guest from 184.72.82.126
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

    
How to solve mod_rewrite something?
designaweb




msg:1508676
 2:34 pm on Dec 7, 2002 (gmt 0)

Hi all!

I have been playing around with mod_rewrite, and I finally manager to do the following thing. I have a dbase driven cheats website, divided into several platforms we enter a section by using "cheats.php?action=showtitles&platform=n64"

Now I wanted to make the url to the Nintendo 64 look like this [thisisnottherealurl.com...] I kinda managed to do this, with the following .htaccess file:


RewriteEngine on
RewriteRule (^(.*)/) cheats.php?action=showtitles&platform=$2 [L]

This works just fine, except for the fact that all links to f.e. the CSS file wich is called by cheats.php is no longer valid, since it is trying to call for /n64/style/1.css instead of /style/1.css

Is there something I can do about this?

 

andreasfriedrich




msg:1508677
 2:47 pm on Dec 7, 2002 (gmt 0)

RewriteEngine on
RewriteCond %{REQUEST_URI} !\.(css¦js)
RewriteRule ^(.*)/ cheats.php?action=showtitles&platform=$2 [L]

This will do the rewriting only if both the rewritecond condition and the rewriterule match. The RewriteCond matches any URI that does not contain .css or .js.

Andreas


Note: The WebmasterWorld posting software deletes spaces preceding the exclamation point "!" character. It also replaces a solid vertical pipe symbol with a broken vertical pipe "¦" symbol. Both of these changes will need to be undone in any code you copy from WebmasterWorld. Make sure to include a space preceding the "!" in mod_rewrite code, and always replace "¦" with a solid vertical pipe.
jdMorgan




msg:1508678
 3:02 pm on Dec 7, 2002 (gmt 0)

Andreas,
I think it should now read:

RewriteEngine on
RewriteCond %{REQUEST_URI} !\.(css¦js)
RewriteRule ^(.*)/ cheats.php?action=showtitles&platform=[b]$1[/b] [L]

?
Jim

andreasfriedrich




msg:1508679
 3:12 pm on Dec 7, 2002 (gmt 0)

You are right Jim. When I deleted designaweb´s outer parens I would have had to change $2 to $1.

Thanks Jim

designaweb




msg:1508680
 3:21 pm on Dec 7, 2002 (gmt 0)

What I mean was, all links (to images, to other pages, to CSS files) cannot be used relative anymore, since cheats.php is stored in www.domain.com/test/, but because it's called in www.domain.com/test/n64/ the links that where in cheats.php cannot be used relative... Am I correct?

andreasfriedrich




msg:1508681
 3:36 pm on Dec 7, 2002 (gmt 0)

They can still be relative. You just need to consider the extra directory n64 in your URL. Unless you specify a base URI explicitly the base used to resolve relative URIs will be [domain.tld...] Use <img src="../images/test.gif" /> to reference the image test in /test/images/test.gif.

Andreas

designaweb




msg:1508682
 3:38 pm on Dec 7, 2002 (gmt 0)

Yes, and that is exactly my point. cheats.php will be called from /test/n64/, but also from /test/dreamcast/, and also from /tets/n64/A/.

Isn't there a way to make cheats.php remember it's original (and real) location?

andreasfriedrich




msg:1508683
 3:51 pm on Dec 7, 2002 (gmt 0)

There is. Set the base URI explicitly:

<base href="http://www.domain.tld/test/" />

Now all relative URIs will be resolved relative to that URI.

<img src="images/test.gif" /> will always be resolved to [domain.tld...] no matter whether the actual URI cheats.php was accessed by is /test/dreamcast/ or /tets/n64/A/.

Andreas

designaweb




msg:1508684
 3:56 pm on Dec 7, 2002 (gmt 0)

Ah, thanx...

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