在自己的文件夹中重写为Codeigniter系统


.htaccess Rewrite to Codeigniter system in its own folder

我构建了一个没有MVC框架的开源系统。到了升级系统的时候了,我把它重新构建成Codeigniter MVC框架。

系统位于/ci文件夹中。由于技术原因,它应该留在这个文件夹。

我已经在route文件夹中设置了正确的。htaccess以使其工作:

    RewriteEngine on
# Change example.com to be your main domain.
RewriteCond %{HTTP_HOST} ^(www.)?domain.com$
# Change 'subdirectory' to be the directory you will use for your main domain.
RewriteCond %{REQUEST_URI} !^/ci/
# Don't change the following two lines.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Change 'subdirectory' to be the directory you will use for your main domain.
RewriteRule ^(.*)$ /ci/$1
# Change example.com to be your main domain again.
# Change 'subdirectory' to be the directory you will use for your main domain
# followed by / then the main file for your site, index.php, index.html, etc.
RewriteCond %{HTTP_HOST} ^(www.)?domain.com$
RewriteRule ^(/)?$ ci/index.php [L] 
RewriteRule ^/member$ /member [L]
RewriteRule ^/ad_images$ /ad_images [L]
RewriteRule ^/ad_images/130$ /ad_images/130 [L]
RewriteRule ^/ad_images/116$ /ad_images/116 [L]

我绕过了成员文件夹,因为它仍在使用中,也允许系统使用不同的ad_images文件夹。

我的问题是这样的。旧的网站将有一个链接,看起来像
www.domain.com/vehicles-for-sale

在新系统中,这个链接实际上是

www.domain.com/categories/1-0-0-0

我将需要做一个永久移动旧的url到新的。

为什么将此添加到。htaccess文件不起作用,我应该如何编写它才能达到预期的效果?

RewriteRule ^/vehicles-for-sale$ /ci/categories/index/3-0-0-0 [L]

应该省略第一个斜杠。如果你想做一个永久的重定向,使用R=301标志。此外,您现在正在重写为ci/categories/index/3-0-0-0,而不是所需的categories/1-0-0-0

这应该为您工作:

RewriteRule ^vehicles-for-sale$ /categories/1-0-0-0 [L,R=301]