简体   繁体   English

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

[英].htaccess Rewrite to Codeigniter system in its own folder

I built an open-source system without a MVC framework. 我建立了一个没有MVC框架的开源系统。 It became time to upgrade the system and I rebuilt it into the Codeigniter MVC framework. 到了升级系统的时候了,我将其重建为Codeigniter MVC框架。

The system is located in the /ci folder. 系统位于/ ci文件夹中。 For technical reason it should stay in this folder. 由于技术原因,它应保留在此文件夹中。

I have set up the correct .htaccess in route folder to make this work: 我已经在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]

I am bypassing the member folder as Its still in use and also allow the system to make use of the different ad_images folders. 我绕过了仍在使用的成员文件夹,并且还允许系统利用不同的ad_images文件夹。

My problem is this. 我的问题是这个。 The old site will have a link that looks like 旧网站的链接看起来像

www.domain.com/vehicles-for-sale www.domain.com/vehicles-for-sale

In the new system this link is actually 在新系统中,该链接实际上是

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

I will need to do a permanently move the old url to the new. 我将需要将旧网址永久性地移动到新网址。

Why would adding this to the .htaccess file not work and how should I write it do have the desired effect? 为什么将其添加到.htaccess文件不起作用,我应该如何编写才能达到预期的效果?

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

You should omit the first slash. 您应该省略第一个斜杠。 And if you want to do a permanent redirect, use the R=301 flag. 如果要进行永久重定向,请使用R=301标志。 Furthermore, you are rewriting to ci/categories/index/3-0-0-0 now, instead of the desired categories/1-0-0-0 . 此外,您现在正在重写为ci/categories/index/3-0-0-0 ,而不是所需的categories/1-0-0-0

This should work for you: 这应该为您工作:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM