TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Advanced PHP Programming (http://www.talkphp.com/advanced-php-programming/)
-   -   .htaccess, rewriting url (http://www.talkphp.com/advanced-php-programming/5176-htaccess-rewriting-url.html)

ReSpawN 12-20-2009 02:56 PM

.htaccess, rewriting url
 
I've been trying to rewrite my url to do the following.

I've got a file (image) stored in /gallery/media/avatar/n/r/ and the filename respawn.jpg. Through .htaccess, I would like to aproach the URL through this url: http://avatar.domain.tld/n/r/respawn.jpg

The question is, how? My script keeps rewriting the URL. I can aproach it, but the URL changes upon find.

PHP Code:

RewriteCond %{HTTP_HOST}     ^avatar\.domain\.tld$ [NC]
RewriteCond %{REQUEST_URI}     ^/avatar/(.*)/(.*)/(.*) [NC]
RewriteRule (.*) http://www.google.nl/$1/$2 [NC] 

Do not mind the google.nl part, that was just for testing. I feel like I am on the righ track, but I can't seem to get it to work.

I followed some instructions on http://corz.org/serv/tricks/htaccess2.php, perhaps someone can use it.

Looking forward to some responses.

ReSpawN

delayedinsanity 12-23-2009 01:06 AM

The first problem is probably that you're capturing three groups, and only returning two.

php Code:
RewriteCond %{HTTP_HOST} ^avatar.domain.tld$ [NC]
RewriteRule ^/([_0-9a-zA-Z-]+/)?([_0-9a-zA-Z-]+/)?([^.]+\.[A-Za-z]{3,4})$ http://www.domain.tld/avatar/$1$2$3
 

I don't know your specific needs, so I just wrote it based off your existing rules. This should grab any address from http://avatar.domain.tld/something/s.../something.ext and find the actual file at http://www.domain.tld/avatar/somethi.../something.ext (untested). Modify to suit your needs. :)


All times are GMT. The time now is 07:36 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0