Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Jan 2010
    Posts
    101
    Thanks
    17
    Thanked 5 Times in 5 Posts

    Short URLs with similar directories

    Here's what I need, I'm trying to make short urls available for users on my domain. For example: domain.com/user. Yes, this is a necessary function of my site, not just for convenience. The problem is I also have directories in my root directory that could mimic these usernames without being related at all (for example, /css or /images), see how those could both be usernames? How can I avoid this problem?

  • #2
    New Coder
    Join Date
    Jul 2011
    Posts
    67
    Thanks
    0
    Thanked 13 Times in 13 Posts
    Use RewriteConds to either explicitly avoid the actual URLs or perhaps more convenient, don't rewrite if the request file actually exists.

    Code:
    RewriteCond %{REQUEST_URI} !-f
    RewriteCond %{REQUEST_URI} !-d
    RewriteRule ^([^/.]+)$ /index.php?user=$1 [L]

  • #3
    Regular Coder
    Join Date
    Jan 2010
    Posts
    101
    Thanks
    17
    Thanked 5 Times in 5 Posts
    Quote Originally Posted by Cags View Post
    Use RewriteConds to either explicitly avoid the actual URLs or perhaps more convenient, don't rewrite if the request file actually exists.

    Code:
    RewriteCond %{REQUEST_URI} !-f
    RewriteCond %{REQUEST_URI} !-d
    RewriteRule ^([^/.]+)$ /index.php?user=$1 [L]
    Ahh great! Thank you, looks like I'll have to disallow certain usernames... Shouldn't be a big problem!

  • #4
    New Coder
    Join Date
    Jul 2011
    Posts
    67
    Thanks
    0
    Thanked 13 Times in 13 Posts
    Indeed, I meant to mention that you would have to either pre-register certain nicknames, or have a black list that isn't usable. Alternatively you could use a different subdomain allowing full usage of all paths.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •