加载位于博客文件夹外的index.php内容,用于发布单页

Sre*_*ree 11 php wordpress .htaccess mod-rewrite redirect

我正在为我的静态PHP网站创建WordPress的博客页面.当博客页面URL更改为pretty permalink(example.com/blog/my-post-page)时,加载内容(不重定向到index.php,只有内容加载和URL将像http://example.com/blog/my-post-page)index.php(我的网站的主页))位于博客文件夹之外而不是single.php内容.

永久链接更改为default(example.com/blog/?p=123)时,它将完美地工作.

我需要网址为http://example.com/blog/my-post-page.

编辑: - 我更新了定制结构的固定链接/index.php/%postname%/.但现在帖子页面正在显示example.com/blog/index.php/my-post-page.

我认为新的WordPress版本引发了这个问题.(版本4.2.2).任何index.php从URL中删除的解决方案?

我的目录结构: -

/                                          - 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)
Run Code Online (Sandbox Code Playgroud)

我的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>
Run Code Online (Sandbox Code Playgroud)

当我在根文件夹中删除/重命名index.php时,页面将显示未找到错误.

ank*_*jbp 2

应该有效

<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>
Run Code Online (Sandbox Code Playgroud)

  • 与您的情况非常相似,看看 https://wordpress.org/support/topic/pretty-permalinks-redirects-to-indexphp (5认同)
  • 是的。从上面的链接我已将永久链接更新为自定义 /index.php/%postname%/。但现在帖子页面显示为 example.com/blog/index.php/my-post-page。如何去除它? (2认同)