Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

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.

like image 834
Sree Avatar asked May 15 '15 09:05

Sree


2 Answers

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
like image 89
JNZ Avatar answered Nov 07 '22 07:11

JNZ


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>
like image 38
ankit.jbp Avatar answered Nov 07 '22 09:11

ankit.jbp