duanjie6912 2019-06-10 21:21
浏览 78

查询字符串不工作的Mod Rewrite规则/ WordPress,Apache,Virtualmin

I have an .htaccess rewrite rule that should be simple but is not working.

RewriteRule ^advisors/(.+)/about/ /advisor_master/about/?advisor=$1 [NC,L]

This should map the URL such as:

/advisors/stevens-group/about/ to /advisor_master/about/?advisor=stevens-group

However, the page displays a 404 error.

Now, if I go to the URL /advisor_master/about/?advisor=stevens-group directly, it displays fine.

Troubleshooting I've already tried:

If I update the Rewrite rule to be without the query string in the destination path, like this:

RewriteRule ^advisors/(.+)/about/ /advisor_master/about/ [NC,L]

it does not display a 404 error but instead loads the page correctly except without the query string data. Of course I need this query string data so this isn't good enough.

I've also tried the following in my WordPress functions.php file:

function init_custom_advisor_rewrite() {

        add_rewrite_rule(        
            '^advisors/([^/]+)/about/',        
            'index.php?page_id=1049&advisor=$matches[1]',       
            'top' );
}
add_action( 'init', 'init_custom_advisor_rewrite' );

I re-saved permalink settings. This does not work either, it still displays a 404 page. If I open the URL in the browser directly:

/index.php?page_id=1049&advisor=stevens-group

This redirects to the correct custom page template:

/advisor_master/about/?advisor=stevens-group

and works as it should. Also if I drop the query string from the add_rewrite_rule() function like in my .htaccess file, it works there too. However I need that query string for dynamic data.

Edit: Another idea was to see if query string values work if accessing a script file directly, e.g., /test.php?advisor=stevens-group outside of WordPress. This does work correctly and the query string is accessible. So, this means the issue is related to the WP permalink or mapping structure.

The setup is on Apache2 on a Virtualmin server running Ubunutu 18.

Here are the apache directory settings:

Options -Indexes +IncludesNOEXEC +SymLinksIfOwnerMatch +ExecCGI
allow from all
AllowOverride All Options=ExecCGI,Includes,IncludesNOEXEC,Indexes,MultiViews,Sy$
Require all granted
AddType application/x-httpd-php .php

Any suggestions?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 对于这个复杂问题的解释说明
    • ¥50 三种调度算法报错 采用的你的方案
    • ¥15 关于#python#的问题,请各位专家解答!
    • ¥200 询问:python实现大地主题正反算的程序设计,有偿
    • ¥15 smptlib使用465端口发送邮件失败
    • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
    • ¥15 对于squad数据集的基于bert模型的微调
    • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
    • ¥20 steam下载游戏占用内存
    • ¥15 CST保存项目时失败