Welcome to WebmasterWorld Guest from 54.161.227.32

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

How to solve mod_rewrite something?

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

Preferred Member

10+ Year Member

joined:Dec 5, 2002
posts:367
votes: 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?

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

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:July 22, 2002
posts:1782
votes: 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.
3:02 pm on Dec 7, 2002 (gmt 0)

Senior Member

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

joined:Mar 31, 2002
posts:25430
votes: 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
3:12 pm on Dec 7, 2002 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:July 22, 2002
posts:1782
votes: 0


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

Thanks Jim

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

Preferred Member

10+ Year Member

joined:Dec 5, 2002
posts:367
votes: 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?
3:36 pm on Dec 7, 2002 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:July 22, 2002
posts:1782
votes: 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

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

Preferred Member

10+ Year Member

joined:Dec 5, 2002
posts:367
votes: 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?

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

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:July 22, 2002
posts:1782
votes: 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

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

Preferred Member

10+ Year Member

joined:Dec 5, 2002
posts:367
votes: 0


Ah, thanx...
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members