我怎么改写
www.mysite.com/someURLhere
成
www.mysite.com/ping.php?url=someURLhere
没有错误的本地文件,目录作为域。
所以我不想要
www.mysite.com/index.php www.mysite.com/admin/
重写
www.mysite.com/ping.php?url=index.php www.mysite.com/ping.php?url=admin/
试试这个被黑客入侵的joomla的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]
我可能会更容易redirect在实际上不存在的“虚拟”子文件夹中的url。 我不确定这是否适用于您的devise,但是我绝对推荐您考虑这一点,因为在编写重写规则时它会让您的生活更轻松,并且还可以防止您意外地重写存在的文件。
www.mysite.com/p/someURLhere
(其中/ p /实际上不存在于文件系统中)redirect到www.mysite.com/ping.php?url=someURLhere
那么你的重写规则将需要更less的条件。
DennyHalim说的
我多砍了一点(没有尝试,但看起来是正确的:s)
RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_URI} !^/ping.php RewriteCond %{REQUEST_URI} (/.*)$ [NC] RewriteRule ^(.*)$ ping.php?url=$1 [L]
基本上说'如果URL不指向一个存在的文件''如果URL不指向一个存在的目录''如果URL不是'/ping.php'''匹配所有东西''重写“ping.php?URL = $ 1””