SEO and changes to page addresses

- 1 answer

Ad

I have site that has been around for a few years and is pretty well positioned in google search. Now I would like to rebuild the site by introducing a framework. One of the things that framework changes is that everything is routed through index.php and urls are being rewritten.

Currently subpages look like this (example):

mysite.com/home.phpmysite.com/work.php

after the framework introduction they will look like this:

mysite.com/homemysite.com/work

Now can anyone tell me will this hurt/reset page ranks, and if so, how can I make a framework (Yii2) to append .php to controller names and would that be wise...

Ad

Answer

Ad

This is possible with Yii2,

You can create all your pages under the site controller, and add the following to your project:

config/main.php

'urlManager' => [
    'class' => 'yii\web\UrlManager',
    // Disable index.php
    'showScriptName' => false,
    // Disable r= routes
    'enablePrettyUrl' => true,
    // Add suffix
    'suffix' => '.php',
    // General rules, and remove controller name for site
    'rules' => [
        '<controller:\w+>/<id:\d+>' => '<controller>/view',
        '<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
        '<controller:\w+>/<action:\w+>' => '<controller>/<action>',
        '<alias:home|work|etc>' => 'site/<alias>',
    ],
],

.htaccess

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php

Or, if more convenient, create a controller for each of those pages. But you'll figure that out.

Docs: urlManagerurlManager - Suffix

$suffix public property

The URL suffix used when in 'path' format. For example, ".html" can be used so that the URL looks like pointing to a static HTML page. This property is used only if $enablePrettyUrl is true. public string $suffix = null

Ad
source: stackoverflow.com
Ad