Rewrite URL to php

New to mod_rewrite? This is a good place to start.

Rewrite URL to php

Postby bigbob85 » Wed Aug 26, 2009 6:42 pm

Hey,
Wondering if anyone can help me, what i want to do is redirect all traffic on mirror.mysite.com/* to mirror.mysite.com/index.php?path=*

So like
mirror.mysite.com/test/file1.zip, would become
mirror.mysite.com/index.php?path=test/file.zip

What I want to do is have a php script which checks againinst a DB for the string I entered as path, which would then redirect to my download site (rapidshare, mediafire, filesend.. ect ect)

If possible I'd like it to not actualy redirect to the index.php before it redirects to the other site.

Im thinking of something like
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteRule ^([a-zA-Z0-9. //]+)/?$ /index.php?path=$1 [QSA,L]


But im not sure on the other paramaters and stuff.
bigbob85
 
Posts: 2
Joined: Wed Aug 26, 2009 6:32 pm

Postby richardk » Sat Aug 29, 2009 2:30 pm

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

# Don't match internal requests to index.php.
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^(.+)$ /index.php?path=$1 [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby bigbob85 » Sat Aug 29, 2009 7:02 pm

Thank you alot! This works perfectly :)

EDIT:
Well, it works perfectly on my local host.. dosnt work at all on my real server. When I try it, it gives "The requested URL /<the file I used> was not found on this server."

EDIT2:
Fixed it by not using .htaccess files, but rather in the server config for this virutal host.
bigbob85
 
Posts: 2
Joined: Wed Aug 26, 2009 6:32 pm


Return to Beginner's Corner

Who is online

Users browsing this forum: No registered users and 28 guests

cron