Hi,
I´m newbie to mod rewrite, and although I have a solution it isn´t working. I think this is very simple to who know how
I´m trying to configure wordpress in a already built site, for the two site to be able to be on same host, I renamed index.php of worpress to index2.php and disable pretty urls.
so the worpress url will be
http://www.example.com/index2.php
and the links in worpress will be
http://www.example.com/?page_id=5215
My problema is that because I want wordpress to assume the link, the correct url should be
http://www.example.com/index2.php?page_id=5215
So I need that apache to replace url each time it was page_id= to index2.php?page_id= like the two above links
I need the changes to be in httpd.conf, inside a directory tag and have this solution
RewriteEngine on
RewriteBase /
RewriteRule ^page_id=(.*)$ /index2\\.php?page_id=$1
I believe you will want the following, as your page request won’t begin with page_id, I also don’t think you need to escape the . in the index2.php?page_id=$1
Okay, I know where I went wrong now. It seems RewriteRules do not execute against a query string. You must use a RewriteCond for that. So here is the final code
RewriteEngine on
RewriteCond %{QUERY_STRING} ^page_id=[0-9]+
RewriteRule index\\.php index2.php
The reason is that a RewriteRule cannot access the query string, only the path/file of the request. Therefore, the RewriteCond statement is REQUIRED.
If you would like to learn something about mod_rewrite, try my signature’s link. It’s been active here for quite a few years and has helped many members.
The leading / in the redirection is a two-edged sword: mod_rewrite will look first at the root of the server THEN to your DocumentRoot. Best to omit the leading /. It’s your choice but you needed the “food for thought.”