Forum Moderators: phranque

Message Too Old, No Replies

mod rewrite Issues

Rewriting questions

         

kerplunk

5:56 am on May 17, 2007 (gmt 0)

10+ Year Member



We're having a little trouble with mod_rewrite, I think. I'm not familiar with mod_rewrite, but here's what we're trying to do:

We have user profiles on our site. The URLs are http://www.example.com/profiles/username-here

We've been using the Apache/mod_rewrite configuration below, and it works, but is it the best way to do what we're trying to achieve? Especially for a high-traffic site? Another problem is that we get a ton of "File not found" errors in our Apache error_log, even though the URL works correctly.


<VirtualHost 1.2.3.4>
DocumentRoot /directory/to/our/site/here
ServerName www.example.com
ServerAlias www.example.com
<Location / >
RewriteEngine on
RewriteCond %{REQUEST_FILENAME}!-f
RewriteCond %{REQUEST_FILENAME}!-d
</Location>
<Location /profiles/ >
RewriteEngine on
RewriteCond %{REQUEST_FILENAME}!-f
RewriteCond %{REQUEST_FILENAME}!-d
RewriteRule!\.(js¦ico¦gif¦jpg¦png¦css)$ /profiles/index.php
</Location>
ErrorDocument 404 /404.html
</VirtualHost>

Any suggestions would be appreciated. Thanks!

[edited by: jdMorgan at 3:24 pm (utc) on May 17, 2007]
[edit reason] Example.com [/edit]

phranque

9:26 am on May 17, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



..., but here's what we're trying to do:

..., but is it the best way to do what we're trying to achieve?

you haven't actually described what you are trying to do.
also an examplified url that fails and the corresponding error log message would help.
and can we assume this is in the server config file vs. the per-directory files?

jdMorgan

3:25 pm on May 17, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



And note that there is no RewriteRule in the first <Location> container, so the RewriteConds do nothing.

Jim

kerplunk

6:16 pm on May 17, 2007 (gmt 0)

10+ Year Member



Hi,

I'm just trying to accomplish:

If someone goes to http://www.example.com/profiles/whatever-here that it gets directed to http://www.example.com/profiles/index.php and that will handle it...

I think :)

[edited by: jdMorgan at 6:27 pm (utc) on May 17, 2007]
[edit reason] Example.com [/edit]

kerplunk

6:17 pm on May 17, 2007 (gmt 0)

10+ Year Member



(The URL should still show as: http://www.example.com/profiles/whatever-here)

[edited by: jdMorgan at 6:27 pm (utc) on May 17, 2007]
[edit reason] Example.com, Please see TOS. [/edit]

kerplunk

6:47 pm on May 17, 2007 (gmt 0)

10+ Year Member



Sorry to post again, but I think this would work, right?

<Location /profiles/ >
RewriteEngine On
RewriteCond %{REQUEST_URI}!^/profiles/index.php$
RewriteRule .* /profiles/index.php
</Location>

jdMorgan

9:21 pm on May 17, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Looks OK, what were the results of testing it?

Jim

kerplunk

2:30 am on May 18, 2007 (gmt 0)

10+ Year Member



It's working good :)

Still getting some "File not found" errors, but I am guessing that has to do with our site code and not mod_rewrite.

Thanks for the help, though.

g1smd

11:55 pm on May 18, 2007 (gmt 0)

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



Just to be picky with terminology...

If you still want the original URL to show up then that is a rewrite not a redirect.