开发者

redirect to member page

I'm putting together user pages based on the us开发者_高级运维ername in the URL. for example blank.com/username

I was able to get a script to get the user name:

$pageName = basename($_SERVER["REQUEST_URI"]);

now, when you got to blank.com/username it obviously takes you to a page that doesn't exist. how do I redirect to the page they are suppose to go to?


Try using .htaccess to send the requests to your desired PHP file. This is assuming your server is running Apache and supports mod_rewrite.

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/index.php
RewriteCond %{REQUEST_URI} (/|\.php|\.html|\.htm|\.feed|\.pdf|\.raw|/[^.]*)$ [NC]
RewriteRule (.*) index.php

index.php is the file with your $pageName = basename($_SERVER["REQUEST_URI"]);


Why not provide a redirect header like this

header('Location:Your URL');

This has to be before any echo statements in the code.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜