rewrite user url

Discuss practical ways rearrange URLs using mod_rewrite.

rewrite user url

Postby acctman » Tue Jul 29, 2008 5:02 pm

can someone help me rewrite the user url from http://www.domain.com/view/USER.html to http://www.domain.com/USER/ or http://www.domain.com/USER

so if a user types in http://www.domain.com/USER internally the user is sent to http://www.domain.com/view/USER.html, but I would also need to omit folders such at CHAT, TEMP, FORUMS, etc from being rewritten
Code: Select all
<IfModule mod_rewrite.c>
RewriteEngine On      
RewriteBase /

# force www   
RewriteCond %{HTTP_HOST} !^www\.domain\.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]
# end www
      
# start underscore -> dash conversion
RewriteRule !\.(html|php)$ - [S=4]
RewriteRule ^([^_]*)_([^_]*)_([^_]*)_([^_]*)_(.*)$ $1-$2-$3-$4-$5 [E=uscor:Yes]
RewriteRule ^([^_]*)_([^_]*)_([^_]*)_(.*)$ $1-$2-$3-$4 [E=uscor:Yes]
RewriteRule ^([^_]*)_([^_]*)_(.*)$ $1-$2-$3 [E=uscor:Yes]
RewriteRule ^([^_]*)_(.*)$ $1-$2 [E=uscor:Yes]
   
RewriteCond %{ENV:uscor} ^Yes$
RewriteRule (.*) http://www.domain.com/$1 [R=301,L]
# end underscore
   
RewriteCond %{REQUEST_FILENAME}  !-d
RewriteCond %{REQUEST_FILENAME}  !-f
RewriteCond %{REQUEST_URI} !^ads/
RewriteCond %{REQUEST_URI} !^shop/
RewriteCond %{REQUEST_URI} !^mp3/
RewriteCond %{REQUEST_URI} !^swf/
RewriteCond %{REQUEST_URI} !^js/
RewriteRule ^(.*) index.php [L]
</IfModule>
Last edited by acctman on Wed Jul 30, 2008 8:23 am, edited 1 time in total.
acctman
 
Posts: 5
Joined: Tue Jul 29, 2008 4:13 pm

Postby richardk » Wed Jul 30, 2008 4:08 pm

Try
Code: Select all
Options +FollowSymLinks

<IfModule mod_rewrite.c>
  RewriteEngine On

  # Start underscore -> dash conversion
  RewriteRule ^([^_]*)_([^_]*)_([^_]*)_([^_]*)_(.*\.(html|php))$ http://www.domain.com/$1-$2-$3-$4-$5 [R=301,L]
  RewriteRule ^([^_]*)_([^_]*)_([^_]*)_(.*\.(html|php))$         http://www.domain.com/$1-$2-$3-$4    [R=301,L]
  RewriteRule ^([^_]*)_([^_]*)_(.*\.(html|php))$                 http://www.domain.com/$1-$2-$3       [R=301,L]
  RewriteRule ^([^_]*)_(.*\.(html|php))$                         http://www.domain.com/$1-$2          [R=301,L]

  # Force www   
  RewriteCond %{HTTP_HOST} !^www\.domain\.com$ [NC]
  RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]

  RewriteCond %{REQUEST_URI} !^/(ads|chat|forums|js|mp3|shop|swf|temp)(/.*)?$ [NC}
  RewriteRule ^([^/]+)/?$ /view/$1.html [QSA,L]

  RewriteCond %{REQUEST_FILENAME}  !-d
  RewriteCond %{REQUEST_FILENAME}  !-f
  RewriteRule !^(ads|js|mp3|shop|swf)(/.*)?$ index.php [L]
</IfModule>
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby acctman » Sun Aug 03, 2008 10:21 am

i tried just using this

RewriteRule ^([^/]+)/?$ /view/$1.html [QSA,L]

and got an error, i copied the entire thing and same error
acctman
 
Posts: 5
Joined: Tue Jul 29, 2008 4:13 pm

Postby richardk » Sun Aug 03, 2008 2:42 pm

[NC} should be [NC].

What error are you getting?
What does your error log say is causing the error?
Does the file /view/USER.html exist?
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby acctman » Sun Aug 03, 2008 3:02 pm

I'm getting an Internal Server Error page, sites not loading.
acctman
 
Posts: 5
Joined: Tue Jul 29, 2008 4:13 pm

Postby richardk » Sun Aug 03, 2008 3:04 pm

What does your error log say is causing the error?
Does the file /view/USER.html exist?
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Friendly URLs with Mod_Rewrite

Who is online

Users browsing this forum: No registered users and 80 guests

cron