我在localhost / site上有CodeIgniter,在localhost / site / blog的子目录中有Wordpress。
每个都运行正常 - 除了我希望站点目录中的某些URL指向Wordpress子目录。
我将它们转发到网站文件夹的.htaccess,就像这样(我是一个重写菜鸟):
RewriteEngine On
RedirectMatch Permanent ^/site/about/? /site/blog/about
# Do not enable rewriting for files or directories that exist
RewriteCond $1 !(^site/blog/)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# For reuests that are not actual files or directories,
# Rewrite to index.php/URL
RewriteRule ^(.*)$ index.php/$1 [PT,L]
问题是localhost/site/about/
总是向前转
localhost/site/blog/about/
并更改地址栏。当用户访问localhost/site/blog/about/
时,我需要在localhost/site/about
处提供该页面。
为了在localhost/site/blog/about/
查看页面,我必须在blog子目录中添加RewriteBase指令并更改以下.htaccess中的RewriteRule:
RewriteEngine On
RewriteBase /site/blog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /site/blog/index.php [L]
如果没有此添加,localhost/site/blog/about
处的页面将显示CodeIgniter 404错误页面。 (RewriteBase实际上似乎没有效果)。
最终,该网站将在www.site.com上托管,Wordpress安装将在www.site.com/blog上进行。
我尝试过一系列不同的解决方案,但没有任何效果。任何帮助表示赞赏。
答案 0 :(得分:0)
site/about/
始终转发到site/blog/about/
的原因是因为您已将其告知:RedirectMatch Permanent ^/site/about/? /site/blog/about
要让site/about/
留在网址栏中,但要显示site/blog/about/
中的内容,请执行以下操作:
RewriteEngine On
RewriteRule ^site/about/$ /site/blog/about/ [L]