Redirect URL Rewrite/Map from .htaccess

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?

Read More

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.

Related posts

2 comments

  1. 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.

  2. In case anyone else happens upon this, I have a similar sounding use case where the application code resided inside /public_html/app/ and I wanted it redirect from /public_html/ but not show the app/ portion of it in the url. There was also an additional requirement to not route specific urls in this manner. The resulting file is below. Hopefully it helps someone on a similar journey.

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    
    ## SSL
    RewriteCond %{HTTPS} off 
    RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
    
    ## DO NOT ROUTE THESE DIRECTORIES
    RewriteRule ^(path-1|path-2) - [L]
    
    ## ROUTE OTHER REQUESTS TO /APP
    RewriteCond %{ENV:REDIRECT_STATUS} . [OR]
    RewriteCond %{REQUEST_FILENAME} -f
    RewriteRule ^ - [L]
    RewriteCond %{REQUEST_URI} /(.+)
    RewriteRule !.[a-z0-4]{2,4}$ /app/index.html [NC,L]
    RewriteRule (.*) /app/$1 [L]
    
    </IfModule>
    

Comments are closed.