Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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/
share|improve this question
    
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 9:56

3 Answers 3

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"'

share|improve this answer

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.

share|improve this answer

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]
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.