2013-09-16 18 views
1

我有一个非常简单的网站,有一些静态页面,而且还使用重写规则来拉在数据中的某些动态页面例如:如何保持现有的重写规则与WordPress安装配合使用?

RewriteRule ^phone-directory/([^/\.]+).htm$ number.php?for=$1 [L] 

所以像任何网址:电话目录/谷歌。 htm将始终在查询字符串上加载number.phpgoogle

我已经为CMS功能安装了WordPress,但我仍然需要我的目录在同一时间工作。我也希望该目录使用WordPress主题,以便在网站范围内改变样式!

因此,我在我的WP主题目录中设置了一个自定义模板,并在名为“company-listing”的单词印刷机中设置了一个“页面”。然后,我添加了以下规则来我htaccess文件的顶部:

RewriteRule ^phone-directory/([^/\.]+).htm$ index.php?p=23 [L] 

P = 23指的是我的自定义页面“公司上市”

这重写规则的作品,并带我到“的位置公司列表“,但这就是问题所在,URL重写为domain.com/company-listing

我不希望它这样做。我认为我的重写规则被触发,然后当index.php?p = 23被命中默认的WordPress重写规则触发器。我试过以下几种方法来阻止这种情况发生:

<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteBase/
RewriteCond %{REQUEST_URI} !^/(phone-directory/.*)$ 
RewriteCond %{REQUEST_URI} !^/(index.php?p=23)$ 
RewriteCond %{REQUEST_URI} !^/(company-listing/.*)$ 
RewriteRule ^index\.php$ - [L] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule . /index.php [L] 
</IfModule> 

有什么办法可以解决这个问题吗?要在WordPress中使用自定义模板并将其重写为我选择的网址?总结:

我想:

domain.com/phone-directory/google.htm

加载:

domain.com/index.php?p=23(这是一个“页”在WordPress)

回答

1

你只需要你的WordPress规则之前,有您的规则:

<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteBase/

RewriteRule ^phone-directory/([^/\.]+).htm$ number.php?for=$1 [L] 
RewriteRule ^phone-directory/google.htm$ index.php?p=23 [L] 

RewriteRule ^index\.php$ - [L] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule . /index.php [L] 
</IfModule> 

如果之前的规则之一匹配,只要number.php存在,则wordpress路由规则的!-f条件将失败。

+0

嗨,乔恩。问题是,当index.php?p = 23被击中时....那就是进一步匹配WordPress的规则。这就是为什么从index.php?p = 23,因为它是一个wordpress页面,所以url结束了/ company-listing。 –

+0

@JamesWilson'/index.php?p=23'将匹配'RewriteRule^index \ .php $ - [L]',它会停止完全重写。如果浏览器被重定向,那是因为WordPress正在这样做。 –

+0

是同意的。我已经解决了一些问题。我已经设置了我的重写命令来打开一个名为“directory-listing.php”的新页面,并且在该页面上有一些代码,它执行index.php的file_get_contents?p = 23 - 因此它吸收了正确的内容,并且我动态地更改它,没有任何进一步的重定向! –