简体   繁体   中英

Is it a bad idea to have set my website up like so?

I was thinking of setting up my website with a file called master.php and using .htaccess and URL rewriting I would transform

http://mysite.com/About into http://mysite.com/master.php?selected=About

Which would allow me to setup the about page. Is it a bad idea to have one master page that creates dynamic pages?

No, this is fine. It is called a Front Controller pattern .

Just make sure you direct only page requests this way, and not requests for images, style sheets and other static resources.

完全可以,但是请确保不要将/images/test.png转换为/master.php?selected=images/test.png ,这可能是一个巨大的错误。

I actually use this .htaccess (I use the codeigniter framework, which uses a front controller pattern):

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule (.*) index.php/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
    ErrorDocument 404 /index.php
</IfModule>

So as long as the file or directory does not actually exist, then it's going to get routed through index.php

And actually it's a good design pattern. It actually is easier to maintain in some ways, seeing that urls only have one entry point.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM