按个人资料名称

时间:2015-09-08 11:41:23

标签: php regex .htaccess mod-rewrite

我的网址重写有问题。我想通过用户名获取网址,例如

 yourdomain.com/joshua

但恐怖仍留在404.

的.htaccess

ErrorDocument 404 /eror/404.php
ErrorDocument 403 /eror/403.php
ErrorDocument 500 /eror/403.php

RewriteEngine on
RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://www.recettes.nl/$1 [R,L]
RewriteBase /
RewriteCond  %{REQUEST_FILENAME} !-f
RewriteCond  %{REQUEST_FILENAME} !-d

RewriteRule ^about$ about.php
RewriteRule ^recettes$ recettes.php
RewriteRule ^contact$ contact.php
RewriteRule ^([A-Za-z0-9-]+)/?$ profile.php?user=$1 [QSA,L]
RewriteRule ^recept$ recept.php

RewriteRule ^login$ login.php
RewriteRule ^logout$ logout.php
RewriteRule ^register$ register.php

.profile.php

    if(!(isset($_GET['user']) && $_GET['user'] == $me['id'] || !isset($_GET['user'])) || isset($me)) {
    redirectByPermission('profiles');
}
function notempty($str) {
    return ($str != '');
}
if(isset($_GET['user'])) {
    $user_sql = $dbh->prepare('SELECT * FROM users WHERE id = :id');
    $user_sql->bindParam(':id', trim($_GET['user']), PDO::PARAM_INT);
    $user_sql->execute();
    $user = $user_sql->fetch();
}else{
    $user = $me;
}

有人可以帮我这个并告诉我,我做错了什么?

2 个答案:

答案 0 :(得分:1)

完整的.htaccess:

ErrorDocument 404 /eror/404.php
ErrorDocument 403 /eror/403.php
ErrorDocument 500 /eror/403.php

RewriteEngine on
RewriteBase /

RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=302,L]

RewriteRule ^(about|recettes|contact|login|logout|register)/?$ $1.php [L,NC]

RewriteCond  %{REQUEST_FILENAME} !-f
RewriteCond  %{REQUEST_FILENAME} !-d
RewriteRule ^([A-Za-z0-9-]+)/?$ profile.php?user=$1 [QSA,L]

确保在清除浏览器缓存后对其进行测试。

答案 1 :(得分:0)

试试这个,

RewriteEngine on
RewriteBase /
RewriteCond  %{REQUEST_FILENAME} !-f
RewriteCond  %{REQUEST_FILENAME} !-d
RewriteRule  ^(.*)$ index.php?name=$1 [QSA,L]

希望它会对你有所帮助。