Question: How can i redirect html page extensions to php using proper htaccess redirect as similar to this <http://www.hd2wallpapers.com/butterfly_green-wallpapers.html> gets redirected to <http://www.hd2wallpapers.com/butterfly_green-wallpapers.php>.

Answer: 
Here's yet another way to do something similar with a class decorator—but the aliases aren't specified within the class body like you wanted. It's *very* similar to @BrenBarn's [answer](https://stackoverflow.com/a/19651294/355230), except the aliases are decorator arguments—which I think might be more desirable for some types of usage (and it seems more explicit since it makes them more conspicuous that way).

```
import sys

def aliases(*pseudonyms):
    def aliaser(cls):
        namespace = sys._getframe(1).f_globals  # Caller's globals.
        namespace.update({alias: cls for alias in pseudonyms})
        cls.aliases = pseudonyms
        return cls
    return aliaser

if __name__ == '__main__':
    @aliases('SN', 'FUBAR')
    class LongName(object):
        pass

    print(SN)                # <class '__main__.LongName'>
    print(FUBAR)             # <class '__main__.LongName'>
    print(LongName.aliases)  # ('SN', 'FUBar')

```

#### Update

The [PEP 487](https://www.python.org/dev/peps/pep-0487/) was implemented in Python version 3.6 which allows class customization through inheritance via a new [`__init_subclass__()`](https://docs.python.org/3/reference/datamodel.html#object.__init_subclass__) hook. The code below shows how the same thing could be done using using it.

```
class AKA:
    """ An 'Also Known As' baseclass that allows subclasses to give themselves
        aliases.
    """
    def __init_subclass__(cls, /, aliases=(), **kwargs):
        super().__init_subclass__(**kwargs)
        cls.aliases = aliases
        globals().update({alias: cls for alias in aliases})

if __name__ == '__main__':

    class LongName(AKA, aliases=('SN', 'FUBAR')):
        pass

    print(SN)                # <class '__main__.LongName'>
    print(FUBAR)             # <class '__main__.LongName'>
    print(LongName.aliases)  # ('SN', 'FUBar')

```
> 
> Defining a python class “alias” within the class definition
> -----------------------------------------------------------
> 
> 
> 

I'm just responding to the above problem statement. Martineau's non-accepted answer is close to what I'd do to provide a simple alias. But maybe we don't really want an alias, maybe we really just want to take steps towards getting rid of a bad name.

Naming is hard. Sometimes we wind up with names we'd like to change.

I'm looking at some library code with unfortunately named classes that need deprecation. For example:

```
class BadC: # Bad name, but changing it could break others!
    """Great implementation!"""

```

A multitude of aliases is not helpful, however. Multiple names that point to the same object mean more to learn, and make your code more complex than it needs to be. The bad names need to eventually go away.

I propose the following sort of change as a solution to warn and not break your users:

```
class GoodC:
    """Great implementation!"""

class BadC(GoodC):
    """deprecated, use GoodC instead!"""
    def __init__(self, *args, **kwargs):
        import warnings
        warnings.warn(
          "BadC is deprecated, import and use GoodC instead!",
          DeprecationWarning)
        return super().__init__(*args, **kwargs)

```

Autocomplete will automatically know these names, and introspection (`help(BadC)`) will immediately reveal that you should stop using `BadC`.

Now you can start replacing BadC with GoodC in the rest of your code.

```
>>> GoodC()
<__main__.GoodC object at 0x7f0d0c521c88>

```

and when you or your users use BadC, they'll get their warning:

```
>>> BadC()
__main__:4: UserWarning: The BadC name is deprecated, import and use GoodC instead!
<__main__.BadC object at 0x7f0d0c521cc0>

```

And still be able to continue using it:

```
>>> BadC()
<__main__.BadC object at 0x7f0d0c521c88>

```

Tests will usually show these warnings, or users can enable them, [from the docs](https://docs.python.org/3/library/warnings.html#updating-code-for-new-versions-of-dependencies)

> 
> In the ideal case, the code will have a suitable test suite, and the test runner will take care of implicitly enabling all warnings when running tests (the test runner provided by the unittest module does this).
> 
> 
> In less ideal cases, applications can be checked for use of deprecated interfaces by passing `-Wd` to the Python interpreter (this is shorthand for `-W default`) or setting `PYTHONWARNINGS=default` in the environment. This enables default handling for all warnings, including those that are ignored by default. To change what action is taken for encountered warnings you can change what argument is passed to `-W` (e.g. `-W error`). See the `-W` flag for more details on what is possible.
> 
> 
>