URL重写两个不同的毯子重定向(一个用于WordPress永久链接)

时间:2021-04-05 11:18:33

I have a relatively complex .htaccess file to control page requests, this currently redirects all requests of files (with some type exclusions) to an index file, with an exception of one directory that includes a WordPress installation.

我有一个相对复杂的.htaccess文件来控制页面请求,这当前将所有文件请求(带有一些类型排除)重定向到索引文件,但包含WordPress安装的一个目录除外。

I now need to enable the WordPress PermaLink support but I'm having some difficulty modifying the .htaccess to work.

我现在需要启用WordPress PermaLink支持,但是我在修改.htaccess工作时遇到了一些困难。

The PermaLinks are required to produce more-SEO friendly URLs, and they are normally taken care of exclusively by WordPress - but it my case, it appears that a mod-rewrite rule, as detailed here is required (otherwise, when enabled it gives a 404 response).

PermaLinks需要生成更多SEO友好的URL,并且它们通常由WordPress专门处理 - 但在我的情况下,似乎需要一个mod-rewrite规则,如此处详述(否则,当启用时它会给出一个404响应)。

Here is the current .htaccess contents:

这是当前的.htaccess内容:

RewriteEngine ON

RewriteCond %{HTTP_HOST} !^www\..*
RewriteCond %{HTTP_HOST}   !^$
RewriteCond %{HTTP_HOST} ^([^.]*)\.(co\.uk)
RewriteRule ^.*$     http://www.%1.%2%{REQUEST_URI} [R=permanent,L]

AddHandler application/x-httpd-php .phtml

#RewriteBase /blog/
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
#RewriteRule . /blog/index.php [L]

RewriteBase /
RewriteRule  ^blog/  -  [L]
RewriteRule !\.(js|ico|gif|jpg|JPG|png|css|php|phtml|pdf|txt|xml|swf|flv)$ index.phtml

The commented out section is where I'm trying and failing to add a rule for the WordPress PermaLink functionality.

注释掉的部分是我正在尝试并且未能为WordPress PermaLink功能添加规则的地方。

Initially, I thought this code was working but in fact some non-WordPress requests are still routed to the blog/index.php file and when trying to follow links out of the blog to other site areas these are again being routed back to the blog index.php.

最初,我认为这段代码正在运行,但实际上一些非WordPress请求仍然被路由到blog / index.php文件,当试图将链接从博客中移到其他站点区域时,这些请求再次被路由回到博客index.php文件。

1 个解决方案

#1


Well, I believe I've fixed this now - and the answer in hindsight is glaringly obvious. I've created another .htaccess file in the /blog/ directory and placed the relevant rules in there - seems to work perfectly.

好吧,我相信我现在已经解决了这个问题 - 后见之明的答案非常明显。我在/ blog /目录中创建了另一个.htaccess文件,并在其中放置了相关规则 - 似乎完美无缺。

#1


Well, I believe I've fixed this now - and the answer in hindsight is glaringly obvious. I've created another .htaccess file in the /blog/ directory and placed the relevant rules in there - seems to work perfectly.

好吧,我相信我现在已经解决了这个问题 - 后见之明的答案非常明显。我在/ blog /目录中创建了另一个.htaccess文件,并在其中放置了相关规则 - 似乎完美无缺。