#1
  1. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2008
    Posts
    225
    Rep Power
    8

    .htaccess RewriteRule problems!


    Hey there guys!

    I was wondering does anyone know whats up with my .htaccess RewriteRule code as i cannot get it working as it dosn't redirect to http://mydomain/username/

    Here it is:

    PHP Code:
    Options +FollowSymlinks
    RewriteEngine on
    RewriteCond 
    %{HTTP_HOST} ^www\.(.*) [nc]
    RewriteRule ^(.*)$ http://%1/$1 [r=301,nc]

    RewriteRule ^/(.*)$ /user/$1\.html [R=301,l


    The thing i want to do is that when someone goes on there userpage, origanly created here: http:mydomain.com/user/username.html

    it becomes a 301 dead link as i want http:mydomain.com/username/ to take its place

    Thanks
    Ricky
    Last edited by Toxinhead; April 3rd, 2008 at 02:08 PM.
  2. #2
  3. mod_dev_shed
    Devshed Supreme Being (6500+ posts)

    Join Date
    Sep 2002
    Location
    Atlanta, GA
    Posts
    14,817
    Rep Power
    1099
    A RewriteRule with a pattern that beings with a leading forward slash never matches in the .htaccess context, so RewriteRule ^/... will never match anything.

    Based on what you have, I don't see that you should have problems making /user/username.html redirect to /username/
    Code:
    RewriteRule ^user/([^.]+)\.html$ http://%{HTTP_HOST}/$1/ [R=301,L]
    # Jeremy

    Explain your problem instead of asking how to do what you decided was the solution.
  4. #3
  5. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2008
    Posts
    225
    Rep Power
    8
    Thanks for that it keeps on giving me a 404 error when i go to http://mydomain.com/username ???
    My Cpanel error log files shows this error:

    File does not exist: /home/rickyb/public_html/username


    Any ideas?
    Maybe its something todo with my config files?

    This is my code in my htaccess:
    PHP Code:
    ErrorDocument 401 http://www.mydomain.com/401.html
    ErrorDocument 403 http://www.mydomain.com/403.html
    ErrorDocument 404 http://www.mydomain.com/404.html
    ErrorDocument 500 http://www.mydomain.com/500.html

    AddHandler application/x-httpd-php5 .php .html .htm

    Options 
    +FollowSymlinks
    RewriteEngine on
    RewriteCond 
    %{HTTP_HOST} ^www\.(.*) [nc]
    RewriteRule ^(.*)$ http://%1/$1 [r=301,nc]

    RewriteRule ^user/([^.]+)\.htmlhttp://%{HTTP_HOST}/$1/ [R=301,L] 
    1. gathering 404 links and error files

    2. Making .html, .htm files act like .php files

    3. changing http://www.mydomain.com to http://mydomain.com

    4.trying to make http://mydomain.com/user/username.html go to http://mydomain.com/username


    Thanks heaps
    Ricky
    Last edited by Toxinhead; April 3rd, 2008 at 10:17 PM.
  6. #4
  7. mod_dev_shed
    Devshed Supreme Being (6500+ posts)

    Join Date
    Sep 2002
    Location
    Atlanta, GA
    Posts
    14,817
    Rep Power
    1099
    mod_rewrite is working exactly as it should and is doing what you've told it to do.

    Your problem is that there's no /username/ folder in your DocumentRoot.

    Maybe you're not being clear about how things are setup and what you really want to happen?
    # Jeremy

    Explain your problem instead of asking how to do what you decided was the solution.
  8. #5
  9. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2008
    Posts
    225
    Rep Power
    8
    Originally Posted by jharnois
    mod_rewrite is working exactly as it should and is doing what you've told it to do.

    Your problem is that there's no /username/ folder in your DocumentRoot.

    Maybe you're not being clear about how things are setup and what you really want to happen?
    Yer i do not have a folder named /$username/ as i want it so they can go to a fake folder /$username/ and not having to go to the real url /user/$username.html through RewriteRule?

    Is it possible?

    Thanks
  10. #6
  11. mod_dev_shed
    Devshed Supreme Being (6500+ posts)

    Join Date
    Sep 2002
    Location
    Atlanta, GA
    Posts
    14,817
    Rep Power
    1099
    The thing i want to do is that when someone goes on there userpage, origanly created here: http:mydomain.com/user/username.html


    You have the opposite.

    What you want is basically Example 3 ??? (search on 404) of the MOD REWRITE sticky with just a slight modification.

    Comments on this post

    • Toxinhead agrees : Thanks for your help :)
    # 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