Routing Static Files To New Locations Question

I’m converting a site that has SO much legacy html and my goal is to move all of the html files that are currently mapped to say

FROM www.example.com/test.html to www.example.com/html/test.html

I don’t want old bookmarks or google results to fail. The goal is so that I can replace these eventually with yii views i.e. site\test but for now, the client doesn’t have the money to convert everything (hundreds of files)

Ideally, I want to basically move all of the html files into /html and have routing take care of it

It’d basically be a TODO list of files to convert to yii as financing becomes available.

Yes, I could leave them in the root folder, but it just seems messy.

I was thinking of something like this i.e. in config/main.php:




        'urlManager' => array(

            'urlFormat' => 'path',

            'showScriptName'=>false,

            'rules' => array(

               '<controller:\w+>/<id:\d+>' => '<controller>/view',

               '<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',

               '<controller:\w+>/<action:\w+>' => '<controller>/<action>',


               'test.html'          => 'html/test.html',




or, even better something like

I was thinking of something like this i.e. in config/main.php:




        'urlManager' => array(

            'urlFormat' => 'path',

            'showScriptName'=>false,

            'rules' => array(

               '<controller:\w+>/<id:\d+>' => '<controller>/view',

               '<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',

               '<controller:\w+>/<action:\w+>' => '<controller>/<action>',


               '*.html'          => 'html/*.html',




But, I don’t know how to do this, YET.

Is it possible?

Appreciate your time. Sincerely

-MG

Hi MichaelG.

If you are using Apache web server, the simplest way to redirect the requests is to use rewrite rules in .htaccess file. See for example Apache tips.

In your case you can prepare the following .htaccess file:


Options +FollowSymLinks

RewriteEngine On

RewriteCond %{HTTP_HOST} example.com$ [NC]

RewriteCond %{HTTP_HOST} !html

RewriteRule ^(.*\.html)$ http://example.com/html/$1 [R=301,L]

Place this file in your web site root.

I freely admit that apache .htaccess files are a weakness that I need to work on

I tried this, where http://mg.dev.com/ is mapped as my localhost, and still get a 500 error sadly

Thanks for trying




RewriteEngine on


# if a directory or a file exists, use it directly

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d


# otherwise forward it to index.php

RewriteRule . index.php


Options +FollowSymLinks

RewriteEngine On

RewriteCond %{HTTP_HOST} mg.dev.com/$ [NC]

RewriteCond %{HTTP_HOST} !html

RewriteRule ^(.*\.html)$ http://mg.dev.com//html/$1 [R=301,L]