开发者

How to get rid of backslashes at the back of a url?

Ok actually im not really sure whether the last string in a url is a file or a di开发者_Python百科rectory... for example facebook.com/skaloot. is skaloot a file (facebook.com/skaloot.php) or a directory? (facebook.com/skaloot/index.php) and how do i get rid of ".php" or "/"...

Thank you...


Parsing URLs

$url = 'http://www.example.com/example.php';
$url = substr($url, 0, strrpos($url, '.'));
var_dump($url);
// output is: string(30) "http://www.example.com/example"

URL Rewriting

In your .htaccess file you can use mod_rewrite to rewrite pretty URLs to their actual destination.

For example:

RewriteEngine On
RewriteBase /
# If the URL does not already exist as a file
RewriteCond %{REQUEST_FILENAME} !-f
# or directory
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^example$ /example.php [QSA,L,NC]

The above will direct traffic hitting http://www.example.com/example to your example.php script.

Obviously replace example.com with your domain.

Subdomain option

Another option is to give your users a subdomain each. simon.sklaloot.com for example. I have previously answered a question pertaining to this: Create subdomains on the fly with .htaccess (PHP)

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜