htaccess rewrite url from different pages

前端 未结 1 583
说谎
说谎 2021-01-23 12:03

i make this in htaccess file .. for rewrite url from different page

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{R         


        
相关标签:
1条回答
  • 2021-01-23 12:47

    Your regex patterns match identically, so you're going to need something to differentiate between pages and people (or redirection to profile.php vs. index.php).

    You can accomplish this one of two ways. First, you can go all to one page, let's call it redirect.php. On this page, you could check the id value and then redirect. So like:

        RewriteRule ^([a-zA-Z0-9_-]+)/?$ redirect.php?id=$1
    

    In redirect.php, you grab $_GET['id'] and run some query against it to determine if it's a page or person, and then redirect using something like:

        header("Location: profile.php?username=".$_GET['id']);
    

    If you strictly looking for Facebook related stuff, you can hit the graph API up instead of the database to determine if its a page or person ID. (Not sure if it can exist in both - but I think not).

    If you don't have a database or data source to determine if its a page or person, then you'll need to add something to your URL strings to determine, like /pages/{pageid}, which you could then rewrite your rules to:

        RewriteRule pages/([a-zA-Z0-9_-]+)/?$ index.php?username=$1  # for pages
        RewriteRule ^([a-zA-Z0-9_-]+)/?$ profile.php?username=$1  # for people
    

    If you can't use something in your URL and don't have a way to access it via database, then you're out of luck, as you're hitting two identical patterns.

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