WordPress.org

Ready to get started?Download WordPress

Forums

Mod Rewrite Problems... (10 posts)

  1. Shaney
    Member
    Posted 8 years ago #

    Hello,

    I have modified my WordPress theme so that I can use query strings to insert static content from files onto my WordPress blog using the PHP include(); function.

    For example, http://domain.com/index.php?content=contact would insert the the contents of the file called contact.php into the sidebar of my wordpress blog.

    I am trying to use mod-rewrite to tidy up my URLs, so that http://domain.com/content/contact/ will redirect to http://domain.com/index.php?content=contact

    I have enabled permalinks on WordPress and this is the code that is presently in my .htaaccess file:

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>

    In order to make my non-wordpress mod-rewrite function to work, I have pasted the mod-rewrite code needed above the wordpress generated code:

    RewriteEngine On
    RewriteRule ^content/([^/]*)/$ /index.php?content=$1 [L]

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>

    However, this does not seem to work. When I navigate to the URL: http://domain.com/content/contact/, instead of seeing my contact data included on the page, I see the 404 error file that is apart of my wordpress theme.

    For some unknown reason, it looks as if I cannot get my mod-rewrite function and the wordpress mod-rewrite function to work together.

    I would be grateful if anyone could tell me if I an doing anything wrong - and if so, is there any way I could fix things ?

    Thank you all in advance :)

    EDIT:
    Wordpress: version 2.0.1
    Apache: 1.3.33
    PHP: 4.3.11

    I am not running any WordPress plugins, apart from Askimet.

  2. geoffe
    Member
    Posted 8 years ago #

    I don't understand if or why you are putting your rule ahead of the others in the htaccess file.

    And what code do you have in the WordPress index.php to call the contact.php file?

    Or is this code in sidebar.php as I would expect if this is going into the sidebar?

    And what's the point of using a rewrite rule to pass a variable that is only used to include a file? The user won't see the URI anyway. Are you using permalinks just to code that in?

  3. geoffe
    Member
    Posted 8 years ago #

    ok i see you updated to turn the Rewrite engine on twice. If you are adding your own rules, you should use this:
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]

    RewriteRule ^content/([^/]*)/$ /index.php?content=$1 [L]
    </IfModule>

  4. Direkt
    Member
    Posted 8 years ago #

    Also, don't bother rewriting the rules, since by default, you can do http://url/content/contact and have it work

  5. zeddy
    Member
    Posted 8 years ago #

    Hi,

    I'm newbie. Could you explain me some moments. Where should i place .htaccess file and what is it - </IfModule>. Should i change something in templates?

    I want to make direct links without "?". Such links better for search engines.

  6. Shaney
    Member
    Posted 8 years ago #

    Inside my sidebar.php file I have:

    <?php
    $path = "./";
    $ext = ".php";

    if (preg_match("#^[a-z0-9_-]+$#i", $_GET["page"]) && file_exists($path . $_GET["page"] . $ext)) {
    $filename = $path . $_GET["page"] . $ext;
    include($filename);
    }

    else {

    include("ORIGINAL_SIDEBAR_FILE.php");}

    ?>

    "And what's the point of using a rewrite rule to pass a variable that is only used to include a file? The user won't see the URI anyway. Are you using permalinks just to code that in?"

    The point is that so users can see my wordpress blog with a contact form on the right of the page if they type: mydomain.com/content/contact/

    Or if they type mydomain.com/content/chat/ my wordpress blog will be displayed, with a java chat applet on the right side of the page.

    I have pasted the code you have posted - thank you. However, the same problem still remains.

  7. Shaney
    Member
    Posted 8 years ago #

    "Also, don't bother rewriting the rules, since by default, you can do http://url/content/contact and have it work"

    This does not work when permalinks are enabled in wordpress. Which is the problem I'm trying to solve. It looks as if user created mod rewrite rules are ignored when the wordpress permalinks/rules are turned on.

  8. Direkt
    Member
    Posted 8 years ago #

    It does work, for instance, look at my example:
    http://liquidity.dnsalias.net/static/click

    And the rest of the site is permalink enabled, but I'm using the EzStatic plugin, so thats why it may work for me.

  9. Shaney
    Member
    Posted 8 years ago #

    I shall try the EzStatic plugin later.

    After some Googling, it seems as if I'm not the only one with this issue: http://wordpress.org/support/topic/57249?replies=6

  10. geoffe
    Member
    Posted 8 years ago #

    I'm not sure where to begin on your sidebar.php code.

    I believe what you're doing is requesting from http://domain.com/content/contact/ a file that reads './contact.php' which means it's looking for 'http://domain.com/content/contact/contact.php' Try '/contact.php' which should bring 'http://domain.com/contact.php' although this wouldn't explain your 404 error.

    This whole method still seems bizarre to me. You could just create a static page for contact.php and write in a condition for sidebar.php to say that if this is the contact page, include this contact form code. See here: http://codex.wordpress.org/Conditional_Tags#A_PAGE_Page

    What is the content of the main area if you have a contact page with contact content only in the sidebar?

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags