我正在使用IIS7的共享主机并支持
PHP.我试图用“漂亮的网址”运行一个wordpress博客(删除index.PHP).托管服务提供商不想安装URLRewrite模块,因此我无法使用该选项.我找到了一个wordpress插件,它将从永久链接URL中删除index.PHP,并将404页面更改为index.PHP应该可以做到这一点……这也不起作用.
我熟悉ASP.NET网站的URL重写,但我不确定如何将其用于PHP.托管设置似乎同时支持ASP.NET和PHP,所以我认为可以通过ASP.NET运行重写代码,但我不知道如何去做.
有没有人对这个或任何有关最佳方法的想法有任何经验.如果有什么事情让我朝着正确的方向前进,或者我自己弄清楚了,我会非常乐意在这里为其他可能需要它的人分享这些代码.
解决方法
我在
blog上使用
ManagedFusion Url Rewriter和自定义404错误页面.
ManagedFusion Url Rewriter需要一个名为ManagedFusion.Rewriter.rules的文件来模仿.htaccess,我不得不玩它很多才能做到正确所以我将包括我现在拥有的内容:
# Managed Fusion Url Rewriter # http://managedfusion.com/products/url-rewriter/ # # Developed by: Nick Berardi # Support: support@managedfusion.com # RewriteEngine on # # Place Rules Below # # misc wordpress rewrites RewriteRule ^/wp-login\.PHP$/wp-login.PHP [L] RewriteRule ^/wp-comments-post\.PHP$/wp-comments-post.PHP [L] RewriteRule ^/wp-admin/(.*)$/wp-admin/$1 [L] # deny access to evil robots site rippers offline browsers and other nasty scum RewriteCond %{HTTP_USER_AGENT} ^Anarchie [OR] RewriteCond %{HTTP_USER_AGENT} ^ASPSeek [OR] RewriteCond %{HTTP_USER_AGENT} ^attach [OR] RewriteCond %{HTTP_USER_AGENT} ^autoemailspider [OR] RewriteCond %{HTTP_USER_AGENT} ^Xaldon\ WebSpider [OR] RewriteCond %{HTTP_USER_AGENT} ^Xenu [OR] RewriteCond %{HTTP_USER_AGENT} ^Zeus.*Webster [OR] RewriteCond %{HTTP_USER_AGENT} ^Zeus RewriteRule ^.* - [F,L] # remove www RewriteCond %{HTTP_HOST} ^www\.robboek\.com$[NC] RewriteRule ^(.*)$http://robboek.com$1 [R=301] # redirect old urls RewriteRule ^/2008/12/blog-on-hold.html$/2008/12/12/blog-on-hold/ [R=301] RewriteRule ^/2008/11/google-chrome-wont-start-in-vista-x64\.html$/2008/11/16/google-chrome-wont-start-in-vista-x64/ [R=301] RewriteRule ^/2008/11/pass-community-summit-2008-events.html$/2008/11/14/pass-community-summit-2008-events-calendar/ [R=301] RewriteRule ^/2008/11/fort-stevens-camping-trip.html$/2008/11/14/fort-stevens-camping-trip/ [R=301] RewriteRule ^/2008/10/first-post.html$/2008/10/10/first-post/ [R=301] RewriteRule ^/blog/CommentView,guid,1d8cba50-0814-4c89-86df-eca669973e8e.aspx$/2006/09/29/junctions-in-windows-vista/ [R=301] RewriteRule ^/blog/2006/09/29/JunctionsInWindowsVista.aspx$/2006/09/29/junctions-in-windows-vista/ [R=301] # rewrite all nonexistent files and directories to use index.PHP for wordpress RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$/index.PHP$1
规则处理漂亮的URL,删除www,并重定向以前博客中的几个旧URL.
我还有一个文件“404.PHP”,我已将其设置为我的自定义404错误页面.漂亮的网址不需要这样,但允许您在自定义主题中使用wordpress 404页面.以下是内容:
<?PHP $qs = $_SERVER['QUERY_STRING']; $pos = strrpos($qs,'://'); $pos = strpos($qs,'/',$pos + 4); $_SERVER['REQUEST_URI'] = substr($qs,$pos); $_SERVER['PATH_INFO'] = $_SERVER['REQUEST_URI']; include('index.PHP'); ?>
我希望有所帮助.到目前为止,它对我来说一直很好.
-抢
更新:我刚刚发布了blog article on my experience using WordPress on IIS7