Erialos
Erialos

Reputation: 117

Rewrite rules issue with pretty permalinks in wordpress. Im almost certain my rewrite rules are screwing something up

This is going to be a long post, so please bear with me.

Here is my directory structure

public_html
  agentc0re
    blog

Rewrite rules are enabled and do work.

Rewrite rules for public_html hide agentc0re and redirect to index.php

public_html .htaccess

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?agentc0re.com$ [NC]
RewriteCond %{REQUEST_URI} !^/agentc0re/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /agentc0re/$1 [L]
RewriteCond %{HTTP_HOST} ^(www.)?agentc0re.com$ [NC]
RewriteRule ^(/)?$ agentc0re/index.php [L]
</IfModule>

My index.php is designed such that it loads the specific page & then my header so i have my menu on every page.

http://domain.com/index.php

<?php
        if(isset($_GET['page'])) {$page = $_GET['page'];    /* gets the variable $page */}
        //else{$page = 'index.php';}
        if (!empty($page)) {
            $page .= '.php';
            include($page);
        }   /* if $page has a value, include it */
        else {
            include('home.php');
        }   /* otherwise, include the default page */

        include 'header.php';
?>

This results in loading pages as such, http://domain.com/index.php?page=(blog|forum|....etc)

My agentc0re folder has the following rewrite rules such that it replaces the above with just http://domain.com/(Blog|Forum...etc)

/agentc0re/.htaccess

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /agentc0re/

RewriteCond %{HTTP_HOST} ^(www\.)?agentc0re\.com$ [NC]
RewriteCond %{THE_REQUEST} \s/(index\.php)?[\s?] [NC]
RewriteRule ^ /Home? [R=301,L]

RewriteRule ^Home/?$ /index.php?page= [L]
RewriteRule ^Blog/?$ /index.php?page=blog [L]
RewriteRule ^Forum/?$ /index.php?page=forum [L]
RewriteRule ^SubCounter/?$ /index.php?page=SubCounter/subCounter [L]
RewriteRule ^AboutMe/?$ /index.php?page=aboutme [L]
RewriteRule ^Contact/?$ /index.php?page=contact [L]
</IfModule>

You see i just use an upper case version of the game to differentiate the actual pages, IE blog.php AKA blog(Oh yeah forgot to mention that my above php code removes the .php so i don't need to add it in the rewrite rule)

So now, http://domain.com/Blog works. The formatting sucks but whatever.

Here is the problem

The pretty permalinks do not work when they are enabled.

/agentc0re/blog/.htaccess

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

My Desired Result

When you browse to or click on the link that would take you here:

http://domain.com/Blog/admin/whats-up-world/

Works and goes to the first posting titled "whats up world" My pretty permalinks in wordpress is set to be:

http://domain.com/Blog/%author%/%pagename%/

Alrighty I think the book is done. If you need anymore info let me know.

Hosting through Godaddy if it's to any help.

Thank you!! -Jon

Edit 1

I forgot that i should add two settings that might be relevant to the issue.

Wordpress URL:  http://domain.com/agentc0re/blog
Site URL:  http://domain.com/Blog

Edit 2

Just realized that when you would click on a menu link that it would then "double" that as a new link. IE: you first load http://domain.com/ and you get the home page. Then you click on Blog. It takes you to http://domain.com/Blog, but NOW everything in the menu bar says it will link you do http://domain.com/Blog/(Home|Blog..etc). I don't get it so i took all the rewrite rules for /agentc0re/.htaccess and commented them out for the time being.

Upvotes: 0

Views: 70

Answers (1)

Erialos
Erialos

Reputation: 117

To get pretty perma links to work with my setup all i needed to do was the following super simple change.

My wordpress .htaccess file

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ../index.php?page=blog [L,NC]
</IfModule>

Just needed to change the last line to be MY index.php which has all the includes for my header/menu and stuff.

There are a few issues unresolved, but im considering this answered because my main issue at the time was figuring out how to get the Pretty Permalinks working with my site.

Upvotes: 0

Related Questions