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?