开发者

Directing non extension files to .php

开发者 https://www.devze.com 2022-12-09 18:59 出处:网络
I have a file with .php extention www.example.com/thefile.php?name=123 that I want to direct the user to if the user visits any of the following aliases:

I have a file with .php extention www.example.com/thefile.php?name=123 that I want to direct the user to if the user visits any of the following aliases:

www.example.com/alias?name=123
www.example.com/unreal?name=1开发者_JAVA技巧23
www.example.com/fake?name=123

Is there a way I can get this done without using a framework that already uses this structure? I'm using pure php.


Yes you can, if you have mod_rewrite activated on your Apache Server, you can add a .htaccess file at the root of your website and have something like this into it (not 100% sure since I don't have Apache here at home) :

RewriteRule ^(alias|unreal|fake)$ thefile.php [QSA]

You can consult Apache mod_rewrite doc here


You will have to use mod_rewrite and .htaccess files to achieve this (if you are running Apache that is).


If you are using Apache, you can use mod_rewrite to do this.

A nice article about it: Using htaccess Files for Pretty URLS

0

精彩评论

暂无评论...
验证码 换一张
取 消