在 ASP.NET MVC 站点上设置 Wordpress 永久链接
我有一个 NopCommerce 网站 (ASP.NET MVC
),我正在尝试添加一个 Wordpress 博客作为主网站的子文件夹。
Wordpress 的安装很好,所有配置文件都已创建,如果您浏览博客,博客也可以正常工作。
但是,我现在想通过使用帖子名称来设置漂亮的永久链接。
通常,当您设置永久链接时,它会为 Apache 生成 .htaccess
文件,或为 Windows IIS7 Url Rewrites 生成 web.config
文件。
当我尝试保存永久链接设置时,它会在那里尝试加载并最终超时。
我猜测由于 ASP.NET MVC 使用 Routes
,Wordpress 站点不知道要设置什么。
谁能指导我如何设置永久链接?我是否需要在我的 MVC 站点上设置 Route
?
I've got a NopCommerce site (ASP.NET MVC
) and I'm trying to add a Wordpress blog as a subfolder of the main site.
The installation of Wordpress was fine, all config files have been created and the blog works fine if you browser through it.
However, I now want to setup pretty permalinks by using the name of the post.
Normally when you setup permalinks, it generates either a .htaccess
file for Apache or a web.config
for Windows IIS7 Url Rewrites.
When I try and save the permalink settings, it sits there trying to load and eventually times out.
I'm guessing that because ASP.NET MVC uses Routes
, the Wordpress site doesn't know what to setup.
Can anyone offer me guidance on how I can get the permalinks setup? Do I need to setup a Route
on my MVC site perhaps?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
最后,我从标准 C# 网站上的现有博客之一复制了 web.config 文件。
通常,Wordpress 会自行生成 web.config 文件。我只能假设尚未设置 Wordpress 来处理 .NET MVC 网站上的安装。
在 WordPress 博客文件的根目录中创建一个包含以下代码的 web.config 文件应该可以使其正常工作:
In the end I copied a web.config file from one of my existing blogs that is on a standard C# website.
Normally Wordpress generates the web.config file itself. I can only assume that Wordpress hasn't been setup yet to handle installation on .NET MVC websites.
Creating a web.config file, in the root on the Wordpress blog files, containing the following code should get it working:
如果您在 IIS 上安装 WordPress,您会发现您的友好 URL 不起作用。这是因为 WordPress 想要使用一个名为“mod_rewrite”的 apache 插件。简单来说,它会获取您友好的浏览器 URL,并在后端将它们实际更改为 index.php。此方法的一个问题是 IIS 不加载 apache mod。这是解决此问题的一种简单且免费的方法:
您可以通过右键单击您的 IIS 站点 -> 找到此设置。属性-> ISAPI 过滤器选项卡 ->添加...将过滤器命名为您想要的任何名称,并且可执行文件的路径应该是:
C:\Program Files\Helicon\ISAPI_Rewrite3\ISAPI_Rewrite.dll
单击两个窗口上的“确定”以保存您的设置。
在这里我们将编辑 httpd.conf (注意:这是付费版本和 Lite 版本之间的区别。在付费版本中,您需要编辑 Web 文件夹根目录中的 .htaccess 文件)
重写库 /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?p=$1 [NC,L]
If you install WordPress on IIS you will notice your friendly URLs do not work. This is because WordPress wants to use an apache add-on called “mod_rewrite.” The quick rundown of that this does is it will take your friendly browser URL and actually change them to index.php on the back end. One problem with this method is that IIS does not load apache mods. Here is an easy and free way around this:
You will find this setting by right clicking yourIIS site -> properties -> ISAPI filters tab -> Add … Name the filter whatever you wish and your path to your executable should be:
C:\Program Files\Helicon\ISAPI_Rewrite3\ISAPI_Rewrite.dll
Click OK on both windows to save your settings.
Here we will edit httpd.conf (Note: This is the difference between the pay version and the Lite version. In the pay version you will need to edit the .htaccess file on your web folders root)
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?p=$1 [NC,L]