Forum Moderators: phranque

Message Too Old, No Replies

.htaccess mod rewrite help

shorten URL

         

avr1991

2:07 pm on Jan 21, 2011 (gmt 0)

10+ Year Member



Hi, i've been looking at this forum and seems to have a number of simmilar problems to mine. It sort of works, but not fully

I wanted to get my website from this link (avr1991 being the username):
www.mywebsite.com?p=home&user=avr1991
to:
www.mywebsite.com/avr1991

I have written the code into my .htaccess file
RewriteRule ^([^&]+)/?$ index.php?page=homepage&user=$1

But still does not seem to work.

PS. The topics i have seen have all been something like
www.mywebsite.com/home/user/avr1991
But not a direct link like youtube or facebook

I'd really appriciate any help, thankyou

avr1991

2:19 pm on Jan 21, 2011 (gmt 0)

10+ Year Member



Also it works fine if i do this:
RewriteRule ^folder/([^&]+)/?$ /index.php?page=homepage&user=$1

Then the link would be
mywebsite.com/folder/avr1991

But i need a direct link

avr1991

2:45 pm on Jan 21, 2011 (gmt 0)

10+ Year Member



Sorry for, its SOLVED
[webmasterworld.com...]
But also does anyone know how to only go to that page if there is something there i.e

www.mywebsite.com would not redirect but
www.mywebsite.com/avr1991 would?

g1smd

7:48 pm on Jan 21, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The RewriteRule pattern matches incoming URL requests. If you are not careful it will also match requests for images, scripts, and other requests that it should not match. Adjust the pattern to suit. In particular, it is best for user URLs to all be prefixed with "/u/". In this way the matching rule will be very much more simpler.

avr1991

4:32 pm on Jan 24, 2011 (gmt 0)

10+ Year Member



g1smd yeah thanks, just wanted to do it like facebook or myspace, for users but i did find a way so that it wouldnt redirect all links like images etc...
if you add this
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

It doesn't redirect all scripts

g1smd

7:27 pm on Jan 24, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Look at how they do it at code.google.com:
- /p/ for projects
- /u/ for user profiles
etc.

jdMorgan

1:02 am on Jan 25, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The important thing to ask about code that you "find" is, "What does this code actually do?"

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

The answer is that it invokes two calls in a row to the operating system on your server to check the filesystem --and possibly to go read the physical disk-- for each and every HTTP request that arrives at your server.

As such, it is slow, wastes energy, and may indeed wear out your disk three times faster than normal...

There are usually much much better ways to do what you want without checking the disk for file- and directory-exists all the time. A static exclusion for common image, CSS, JavaScript, document, and multimedia filetypes is usually much to be preferred.... For example:

RewriteCond !^\.(php|gif|jpe?g|png|ico|css|js|xml|pdf|doc|wav|mp[34]|swf|flv|mov|avi|wmv)$

adjusted to suit...

Even if 'exists checks' are actually required, preceding them with this (or a similar) exclusion is almost always possible -- and a very good idea.

Jim