开发者

Showing only top-level for website

I have a website, say accessible under http://example.com. For this, I have several PHP-scripts like index.php, intro.php, faq.php, contact.php etc. So a typical use-case would look like so: User going to http://example.com, which will be http://example.com/index.php -> then clicking on "Introduction" and being redirected to http://example.com/intro.php.

While all this is working nicely, I wondered if there is a way to hide the names of the PHP-sc开发者_开发问答ripts completely, so the URL will always read as http://example.com/, regardless whether the user is on index.php, intro.php, faq.php etc. Using RewriteRules seems not the way to go as it is basically doing the other direction: Facilitating the input of a specific URL for the user (e.g. making the ".php" optional). However, I want the user to get only the URL of the site to be visible and not the individual scripts along its way.

Is something similar actually possible with individual scripts or would this require all the individual scripts to be combined into one and then to use constructs such as:

if( $_POST['destination'] == "intro" )
{
  //DO ALL THE Introduction MARKUP
}

Thank you.

Best.


You could use a full-page iframe, and load intro.php in the iframe. This way, the user stays on the same page, but the page in the iframe changes.


one way (working, but not very good) is to include all your scripts in index.php and call functions which draw specific pages from those scripts. this call s must depend on dome post variable.


You could use AJAX calls to load the new contents when a user clicks on a link. Then you could create your website like usual, but add a script similar to this one (using jQuery):

$(function() {
    $('a').click(function() {
        $.get($(this).attr('src'), function(data) {
            document.write(data);
        });
        return false;
    });
)};

I haven't tried this code, but something along this lines should work.

This would of course not work in browsers that do not support JavaScript, and you would need to take care of forms in another way, so a full-page iframe might be an easier solution.


Given your further explanation, I'd go with the single clean index.php, and other scripts included as needed (I'd even them outside your document root so they can't be accessed directly, either by accident or on purpose):

index.php:

 <?php
 $action = isset($_POST['action']) ? $_POST['action'] :'index';
 switch($action){
       case 'intro':
            require '../pages/intro.php';
            break;
       case 'somethingelse':
            require '../pages/somethingelse.php';
            break;
       case 'index':
       default:
            require '../pages/index.php';
 }
 ?>

Possibly even somewhat optimized with a whitelisted array of possible pages. This keeps your original index.php small & tidy, with still the possibility to do all more complex stuff in dedicated files. No actual need for javascript (it's not needed for the functionality, but of course can be used as desired) or psuedo-hidden urls due to frames (which most of the time doesn't fool a search indexer or someone who just wants to use direct urls with the smallest amount of knowledge about html).

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜