2008-12-30 37 views
6

我使用与IIS7共享主机并支持PHP。我试图运行一个WordPress的博客与“漂亮的网址”(删除index.php)。主机提供商不想安装URLRewrite模块,因此该选项对我无效。我发现了一个wordpress插件,它将从permalink URLs中删除index.php,并将404页面更改为index.php应该做的伎俩......这也不起作用。在IIS7上为Wordpress重写URL

我很熟悉ASP.NET网站的URL重写,但我不确定我会如何去处理它。主机设置似乎同时支持ASP.NET和PHP,所以我认为可以通过ASP.NET运行重写代码,但我不知道如何去做。

有没有人有任何这方面的经验或有关最佳方法的任何想法。如果有任何事情让我朝着正确的方向发展,或者如果我自己想出来的话,我会非常乐意将代码分享给任何可能需要它的人。

回答

4

谢谢大家的建议。

我的主人结束了安装IIRF,它的工作就像一个魅力。有一个名为IsapiRewrite4.ini的文件用于重写规则。为了让我的WordPress安装,而不在URL中的index.php运行时,所有我需要做的就是添加:

RewriteRule ^/sitemap.xml$ - [L] 
RewriteRule ^/(?!index.php)(?!wp-)(.*)$ /index.php/$1 

第一行允许sitemap.xml的文件请求。第二行处理从URL中删除index.php。从性能的角度来看,它似乎也很好,我还没有看到任何页面响应缓慢的问题。

希望这可以帮助其他需要类似功能的人。

5

我用我的blogManagedFusion Url Rewriter自定义404错误页面

的ManagedFusion网址重写需要ManagedFusion.Rewriter.rules文件名为模仿的.htaccess,我必须发挥与它周围相当多的得到它的权利,所以我会包括我目前在矿山:

# Managed Fusion Url Rewriter 
# http://managedfusion.com/products/url-rewriter/ 
# 
# Developed by: Nick Berardi 
#  Support: [email protected] 
# 
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'); 
?> 

我希望有所帮助。到目前为止,它对我来说工作得非常好。

-Rob

更新:我刚刚发布了一个blog article on my experience using WordPress on IIS7

+0

我目前在等待,以了解为什么我的自定义404设置无法正常工作,但一旦它被修复,我会给这个镜头。谢谢! – 2009-01-02 07:20:19

0

改变404页的index.php到是应该做的伎俩。如果没有,该插件可能不支持IIS。

IIS中有一个xml“web.config”文件,用于执行Apache HTTPD中的.htaccess功能。 (即通过静态配置文件覆盖web服务器设置)。它在ASP.NET应用程序中被广泛使用。

请阅读Enable custom errors in WordPress on IIS 7.0 如果这也行不通,您可以尝试要求您的服务提供商为您设置它。 他们可以通过IIS管理控制台GUI配置此设置。