与Joomla和WordPress的mod_rewrite

时间:2013-12-14 13:02:38

标签: wordpress .htaccess mod-rewrite joomla

我有一种Joomla和WordPress mashup。

Joomla站点位于Web根目录(httpdocs目录)中,WordPress站点位于子目录(jobs子目录)中。

我有一个PHP脚本,它使用放在WordPress目录中的长查询字符串:

http://example.com/jobs/search.php?search=true&auth=AUTHCODE&skills=developer&andor=OR&timescale=6&areas=&andor_areas=OR&posted=1

我希望将其重写为:

http://example.com/jobs/search/true/AUTHCODE/developer/OR/6//OR/1

我在网上使用mod_rewrite生成器尝试过很多mod_rewite规则但它们不起作用。我从标准的WordPress警告中找到“找不到页面”。

我在Joomla .htaccess文件和WordPress .htaccess文件中测试了mod_rewite规则。

我尝试使用以下代码的各种不同组合:

RewriteRule ^/jobs/cvsearch/

RewriteRule ^cvsearch/

RewriteRule ^/cvsearch/

在规则开始时没有运气。

我尝试过的一个例子如下,在WordPress .htaccess文件中:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /jobs/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /jobs/index.php [L]
RewriteRule /jobs/search/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)$ /jobs/search.php?search=$1&auth=$2&skills=$3&andor=$4&timescale=$5&areas=$6&andor_areas=$7&posted=$8 [L]
</IfModule>

Joomla .htaccess文件位于下方(与Joomla包一起显示):

##
 # @version $Id: htaccess.txt 10492 2008-07-02 06:38:28Z ircmaxell $
 # @package Joomla
 # @copyright Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved.
 # @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
 # Joomla! is Free Software
 ##


 #####################################################
 #  READ THIS COMPLETELY IF YOU CHOOSE TO USE THIS FILE
 #
 # The line just below this section: 'Options +FollowSymLinks' may cause problems
 # with some server configurations.  It is required for use of mod_rewrite, but may already
 # be set by your server administrator in a way that dissallows changing it in
 # your .htaccess file.  If using it causes your server to error out, comment it out (add # to
 # beginning of line), reload your site in your browser and test your sef url's.  If they work,
 # it has been set by your server administrator and you do not need it set here.
 #
 #####################################################

 ##  Can be commented out if causes errors, see notes above.
 Options +FollowSymLinks

 #
 #  mod_rewrite in use

 RewriteEngine On

 ########## Begin - Rewrite rules to block out some common exploits
 ## If you experience problems on your site block out the operations listed below
 ## This attempts to block the most common type of exploit `attempts` to Joomla!
 #
 # Block out any script trying to set a mosConfig value through the URL
 RewriteCond %{QUERY_STRING} mosConfig_[a-zA-Z_]{1,21}(=|\%3D) [OR]
 # Block out any script trying to base64_encode crap to send via URL
 RewriteCond %{QUERY_STRING} base64_encode.*\(.*\) [OR]
 # Block out any script that includes a <script> tag in URL
 RewriteCond %{QUERY_STRING} (\<|%3C).*script.*(\>|%3E) [NC,OR]
 # Block out any script trying to set a PHP GLOBALS variable via URL
 RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
 # Block out any script trying to modify a _REQUEST variable via URL
 RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
 # Send all blocked request to homepage with 403 Forbidden error!
 RewriteRule ^(.*)$ index.php [F,L]
 #
 ########## End - Rewrite rules to block out some common exploits

 #  Uncomment following line if your webserver's URL
 #  is not directly related to physical file paths.
 #  Update Your Joomla! Directory (just / for root)

 # RewriteBase /


 ########## Begin - Joomla! core SEF Section
 #
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteCond %{REQUEST_URI} !^/index.php
 RewriteCond %{REQUEST_URI} (/|\.php|\.html|\.htm|\.feed|\.pdf|\.raw|/[^.]*)$  [NC]
 RewriteRule (.*) index.php
 RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
 #
 ########## End - Joomla! core SEF Section

RewriteRule中URL的目录部分对我来说是一个令人困惑的部分,因为我不确定它应该如何构建。

此外,Joomla或WordPress .htaccess规则是否会影响我尝试尝试的mod_rewrite?

1 个答案:

答案 0 :(得分:0)

您将mod_rewite规则设置得太低,应该在RewriteBase /jobs/之后。

mod_rewrite规则中缺少插入符号,并已添加到我提供的Apache mod_rewrite .htaccess代码中。您拥有的是:RewriteRule /jobs/search/ etc.但应该是这样:RewriteRule ^/search/ etc.

由于您已将RewriteBase声明为 / jobs / ,因此不需要RewriteRule /jobs/search/ etc.,只需使用RewriteRule ^/search/ etc.减去 / jobs /即可将其更改为部分。

此外,我在mod_rewrite规则中添加了一个临时的307重新直接,非区分大小写的规则。

Apache mod_rewrite .htaccess代码

RewriteEngine On
RewriteBase /jobs/
RewriteRule ^/search/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*) /jobs/search.php?search=$1&auth=$2&skills=$3&andor=$4&timescale=$5&areas=$6&andor_areas=$7&posted=$8 [R=307,NC,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /jobs/index.php [L]