Worpress redirect url

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 :slight_smile:

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

But isn´t working

Can you help me ? Thanks

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

RewriteRule index\\.php?page_id=(.*)$  /index2.php?page_id=$1

or this may work too

RewriteRule page_id=(.*)$  /index2.php?page_id=$1

Hi,
thanks for your reply, but none worked.
THe first I think because the url doesn´t have an index http://www.example.com/?page_id=5215

The second, yes you are right the page doesnt start with page_id ans so I removed the ^, but the result is the same…

Try this:

RewriteRule (?:.*)page_id=(.*)$  /index2.php?page_id=$1

thanks for the help cpradio, but it still doesn´t work.

I’ll play with it when I get home. I don’t have a way of testing my changes here at work.

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

Hi,
thanks but still no luck
the url returned is always like

http://www.example.com/?page_id=4967

instead of

http://www.example.com/index2.php?page_id=4967

mayve the rewrite rule needs to have the full url ?

:tup:

Finally, the correct solution!

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.

ReRegards

DK

Thanks,
I´ve saw your links yesterday, in another forum posts, but they were dead. Now they are working, i´ve checked :wink:

You say “Finally, the correct solution!” but I dont see it :slight_smile:

Can you help ? Thanks

I´ve done it :smiley:

here is the final code

   RewriteEngine  on
   RewriteCond %{QUERY_STRING} ^page_id=[0-9]+
   RewriteRule ^$ /index2.php

Managed twith code from cpradio and a read through dklynn articles.

Thanks to both for your time

jc,

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.”

Regards,

DK

thanks :slight_smile: