Redirect URL Rewrite/Map from .htaccess

2019-07-22 20:17发布

The problem is, I want to port my current website which is built upon CodeIgniter to WordPress. I do not want to hurt my google ranking and for that, I really need to map certain URLs to an existing file and for new URLs, I will let WordPress handle it in the default way. The main problem that arises is that I do not wish to change the existing domain. I want to redirect/map the files on the same domain from my existing CodeIgniter project.

Okay, let me make it a bit more clear about the state of my problem. I copied my existing CodeIgniter project into the WordPress root folder. Now, I will let the old URL being served from my CodeIgniter project and for all the new ones I will let WordPress handle it. I will also port the existing database to the new server and create a separate one for the WordPress installation. So, how can I map my old URLs to the CodeIgniter?

My old URLs looks something like this,

http://www.example.com/site/blog/123/abc-xyz-wxy

I want to handle these URL from CodeIgniter file and the new URLs that will be created by WordPress will be handled by WordPress which would look like this,

http://www.example.com/abc-xyz-wxy

So, far this is how my .htaccess file looks like,

BEGIN WordPress

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /cms/wordpress/
RewriteRule ^site/blog/([0-9]+)/([a-zA-Z0-9-]+)/?$ codeignitor/index.php/$2 
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /cms/wordpress/index.php [L]
</IfModule>

END WordPress

And this thing works absolutely fine, but what I want is more of a URL masking. I want to eliminate the CodeIgnitor folder name from the URL.

1条回答
时光不老,我们不散
2楼-- · 2019-07-22 20:33

For selecting the "abc-xyz-wxy" string and redirecting, try using:

RewriteCond %{REQUEST_FILE} !-f
RewriteCond %{REQUEST_FILE} !-d
RewriteRule ^site\/blog\/123\/([a-z-]+) index.php\/$1 [NC,L] ^$1

Disclaimer: Never used CodeIgniter, so everyone feel free to correct.

查看更多
登录 后发表回答