.htaccess codeigniter重定向而不更改URL


.htaccess codeigniter redirection without changing URL

我有这个htaccess代码。我想要实现的是能够将请求重定向到/wordpress文件夹的内容,而无需更改地址栏

#Rewrite engine rules
RewriteEngine on
RewriteBase /
RewriteCond $1 !^(index'.php|import'.php|geocode'.php|robots'.txt|BingSiteAuth'.xml|y_key_88c0d00f4917d584'.html|favicon'.ico|images|img|uploads|css|js|topics|wordpress)
RewriteRule ^(.*)$ /index.php/$1 [L]
RewriteRule ^about$ /wordpress [L]
RewriteRule ^learn$ /wordpress [L]

具有以下结构,以/content作为web根:

/content
 /wordpress
  index.php (the wordpress index.php)
 .htaccess (the one we are editing)
 index.php (the codeigniter index.php)

但是,htaccess代码不起作用。

尝试将特定规则移动到通配符规则之上。

目前您有

RewriteRule ^(.*)$ /index.php/$1 [L]

在您的特定规则之前,将首先触发此规则。至于您的特定规则(关于/学习),您可能需要重定向到/wordpress/index.php

请记住,如果您的wordpress文件夹有.htaccess文件,则会使用该文件,而不是CodeIgniter/Root文件,但通过您的文件列表,它似乎没有。

如果重定向到wordpress根目录,地址栏就会发生变化。所以我所做的是在Wordpress中创建一个"学习"answers"关于"页面,让它们进入/Wordpress/relearn和/Wordpress/about。

把它放在你的规则之上(就在RewriteEngine和RewriteBase声明之下):

RewriteRule ^about/$ /wordpress/$1 [L]
RewriteRule ^learn/$ /wordpress/$1 [L]

对/about和/relearn的请求将分别重定向到/wordpress/about或/wordpress/relearn,而不更改地址栏。

注意:这在Chrome中似乎有问题。