mod_rewrite php mysql

前端 未结 4 1778
南旧
南旧 2021-01-16 01:03

I\'m really new at mod_rewrite and i have been trying to figure this out but really stuck. p Here is my issue.

I have a page http://example.com/user/?s=81 ?s=81 is

相关标签:
4条回答
  • 2021-01-16 01:36

    To my knowledge you can not query databases with mod_rewrite.

    how about putting a PHP-script to /user/?s=81, that looks up the user's name in the db and then relocates the user to $url = "/$username"; see PHP's header function passing "Location: $url" to it.

    0 讨论(0)
  • 2021-01-16 01:36

    I have almost sorted it out and here is the solution so far: Here is the .htaccess row

    RewriteRule ^([a-z0-9_-]+)$ user/?s=$1 [L,NC]

    Then in the index file i have the following: $trafikskola_id = mysql_real_escape_string($_GET['s']);

    $vilken_trafikskola = mysql_query("SELECT * FROM users where slug='$trafikskola_id'") or exit(mysql_error());

    In the database i have create slug field and inside that on row 81 added nookie and my url looks like

    http://mypage.com/nookie instead of http://mypage.com/user/?s=81 =))

    However i have the issue that i can not have link http://mypage.com/nookie/ to have a forwardslash

    And aswell non of my css - js - images are working.. Any ideas to solve those issues?

    0 讨论(0)
  • 2021-01-16 01:46

    The other possibility (that I haven't thought through too much :) ) is that you add an extra field to the database e.g. user_home = /nookie/. So the logon script grabs it when verifying account details and thats where you send them to on successful validation? No rewrites /extra scripts needed.

    0 讨论(0)
  • 2021-01-16 01:46

    Here's what I would suggest: if your username is only alphanumeric chars, you could pass the nick to all your Php files, after an internal rewrite, in the GET query.

    Something like:

    RewriteRule /([a-zA-Z0-9]+)$ /user/?s=$1 [QSA,L]
    RewriteRule /([a-zA-Z0-9]+)/(.*)$ /$2?s=$1 [QSA,L]
    

    And then, just have the "mother of mother" classes in Php that check for a value "s" in the query string ($_GET) which checks in the database if the user exists. If the user doesn't exists, make a 404 in Php.

    0 讨论(0)
提交回复
热议问题