SitePoint Sponsor

User Tag List

Results 1 to 13 of 13
  1. #1
    SitePoint Member
    Join Date
    Oct 2007
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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

    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
    Code:
    http://www.example.com/index2.php
    and the links in worpress will be
    Code:
    http://www.example.com/?page_id=5215
    My problema is that because I want wordpress to assume the link, the correct url should be


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

    Code:
    RewriteEngine  on
    RewriteBase /
    RewriteRule ^page_id=(.*)$  /index2\.php?page_id=$1
    But isnīt working

    Can you help me ? Thanks

  2. #2
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,127
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    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
    Code:
    RewriteRule index\.php?page_id=(.*)$  /index2.php?page_id=$1
    or this may work too
    Code:
    RewriteRule page_id=(.*)$  /index2.php?page_id=$1

  3. #3
    SitePoint Member
    Join Date
    Oct 2007
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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..

  4. #4
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,127
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    Try this:
    Code:
    RewriteRule (?:.*)page_id=(.*)$  /index2.php?page_id=$1

  5. #5
    SitePoint Member
    Join Date
    Oct 2007
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks for the help cpradio, but it still doesnīt work.

  6. #6
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,127
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    I'll play with it when I get home. I don't have a way of testing my changes here at work.

  7. #7
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,127
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    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
    Code:
    RewriteEngine  on
    RewriteCond %{QUERY_STRING} ^page_id=[0-9]+
    RewriteRule index\.php index2.php

  8. #8
    SitePoint Member
    Join Date
    Oct 2007
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,
    thanks but still no luck
    the url returned is always like
    Code:
    http://www.example.com/?page_id=4967
    instead of
    Code:
    http://www.example.com/index2.php?page_id=4967
    mayve the rewrite rule needs to have the full url ?

  9. #9
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,653
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)


    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
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  10. #10
    SitePoint Member
    Join Date
    Oct 2007
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks,
    Iīve saw your links yesterday, in another forum posts, but they were dead. Now they are working, iīve checked

    You say "Finally, the correct solution!" but I dont see it

    Can you help ? Thanks

  11. #11
    SitePoint Member
    Join Date
    Oct 2007
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Iīve done it

    here is the final code

    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

  12. #12
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,653
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    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
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  13. #13
    SitePoint Member
    Join Date
    Oct 2007
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •