Loading index.php contents which located outside blog folder for post single page

I’m creating blog page as WordPress for my static PHP website. When blog page URL changes to pretty permalink (example.com/blog/my-post-page), loading contents (not redirecting to index.php, only contents loading and URL will be like http://example.com/blog/my-post-page) of index.php (home page for my site) that is located outside blog folder instead of single.php contents.

When permalink changes to default (example.com/blog/?p=123), it will work perfectly.

Read More

I need URL as http://example.com/blog/my-post-page.

EDIT : – I have updated permalink to Custom Structure as /index.php/%postname%/. But now post pages are showing with example.com/blog/index.php/my-post-page.

I think the issue raised with the new WordPress version. (Version 4.2.2).
Any solutions to remove index.php from URL ?

My Directory Structure:-

/                                          - Root
/blog                                      - Blog folder
/blog/wp-content/themes/mytheme/           - Theme folder
/blog/wp-content/themes/mytheme/single.php - Post Single page

/index.php                                 - Home page (Loading contents of this file)

My htaccess :-

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

When I delete/rename index.php in root folder, page will show not found error.

Related posts

3 comments

  1. in htaccess you can write any regex expression for url rewrite
    in your case

    RewriteRule ^/blog/(.+)$ /blog/index.php?postname=$1
    

    this line means that if url starts with /blog/ anything after / would be passed to /blog/index.php as postname parameter.
    example.com/blog/my-post-page would be rewritten as example.com/blog/index.php?postname=my-post-page

    you can exclude anything from this rule

    for example let’s exclude this: /blog/wp-content/themes/mytheme/
    it would go like this:

    RewriteRule ^(?!/(.+)/(.+)/(.+)/(.+))/blog/(.+)$ /blog/index.php?postname=$1
    
  2. It should work

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /blog/
    RewriteRule ^index.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    
  3. You need to make two changes here, change permalink to /%postname%/.

    and change .htaccess to following

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

Comments are closed.