#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    3
    Rep Power
    0

    .htaccess Vanity URL Causing 404.


    Hi all! I may be a bit late, but happy turkey day!

    I'm trying to add a second Vanity URL the first is declaring the page. I'm trying to allow this for example

    Code:
    http://something.com/page/profilename
    Here is my .htaccess

    Code:
    RewriteEngine On
    RewriteBase /
    RewriteRule ^([a-zA-Z0-9-]+)$ index.php?p=$1&profile=$2 [L]
    RewriteRule ^([a-zA-Z0-9-]+)/$ index.php?p=$1&profile=$2 [L]
    ErrorDocument 404 /redir404.php
    Now my issue is that whenever I try to go to /page/profilename, just to test to see if its setting the $_GET variable, it redirects me to my 404 ErrorDocument.

    Thanks to all who help. And I put this in PHP because of a followup question about interference. But I might already get my answer by chance.

    - Necro
  2. #2
  3. Come play with me!
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    13,745
    Rep Power
    9397
    Is that in /page/.htaccess? What you have doesn't account for the "/page/" part so they won't work if you have it in /.htaccess.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    3
    Rep Power
    0
    Originally Posted by requinix
    Is that in /page/.htaccess? What you have doesn't account for the "/page/" part so they won't work if you have it in /.htaccess.
    No, Its in the root directory. I have a PHP script that takes the GET for p, and specifies what file to include. I asked previously on StackOverflow, but I never got much help. But the guy who answered gave me a sort of working answer.

    He gave me the following,

    Code:
    RewriteRule ^([^/]*)/([^/]*)$ /index.php?p=$1&profile=$2 [L]
    Now the issue I'm having now, is that the website is not including any files. You can see here http://ncms.us/home/123 you can see it finds the 123 being my GET for profile.
  6. #4
  7. mod_dev_shed
    Devshed Supreme Being (6500+ posts)

    Join Date
    Sep 2002
    Location
    Atlanta, GA
    Posts
    14,817
    Rep Power
    1099
    By "not including any files" I'm assuming you're referring to stylesheets, javascripts, and such? With this kind of approach, one would usually include a RewriteCond with the rule to prevent stylesheets and the like from being rewritten, too.
    Code:
    RewriteCond %{REQUEST_URI} !^(stylesheets|javascripts|images)/ [NC]
    RewriteRule ^([^/]*)/([^/]*)$ /index.php?p=$1&profile=$2 [L]
    But since you're talking vanity URLs, I'm assuming they don't exist, so this works well, too:
    Code:
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^([^/]*)/([^/]*)$ /index.php?p=$1&profile=$2 [L]
    It just depends on exactly what you want/need to have happen.
    # Jeremy

    Explain your problem instead of asking how to do what you decided was the solution.

IMN logo majestic logo threadwatch logo seochat tools logo