1

how can i rewrite

www.mysite.com/someURLhere

into

www.mysite.com/ping.php?url=someURLhere

without mistaking local files, and directories as domains.

so i dont want

www.mysite.com/index.php 
www.mysite.com/admin/

to rewrite to

www.mysite.com/ping.php?url=index.php
www.mysite.com/ping.php?url=admin/
  • You might want to mention the webserver you are using since mod_rewrite does exist for more webservers than Apache httpd. – joschi Oct 24 '09 at 09:56

3 Answers3

2

try this hacked joomla's htaccess:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/ping.php
RewriteCond %{REQUEST_URI} (/|\.php|\.html|\.htm|\.feed|\.pdf|\.raw|/[^.]*)$  [NC]
RewriteRule ^(.*)$ ping.php?url=$1 [L]
0

I might be easier to redirect urls in a "virtual" sub folder that does not actually exist. I'm not sure if that will work for your design but I would definitely recommend considering it since it will make your life easier when writing the Rewrite rules and also prevents you from accidently rewriting a file that exists.

www.mysite.com/p/someURLhere

(where /p/ does not actually exist on the filesystem) redirects to www.mysite.com/ping.php?url=someURLhere

Then your rewrite rule would need less conditionals.

emills
  • 774
  • 1
  • 4
  • 15
0

What DennyHalim said

I hacked it a bit more (didn't try it but it looks right :s )

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/ping.php
RewriteCond %{REQUEST_URI} (/.*)$  [NC]
RewriteRule ^(.*)$ ping.php?url=$1 [L]

basically says 'if the url doesn't point to a file that exists' 'if th url doesn't point to a directory that exists' 'if the url is not "/ping.php"' 'match everything' 'rewrite to "ping.php?url=$1"'

phoenix8
  • 213