Forum Moderators: phranque

Message Too Old, No Replies

Whats wrong with this .htaccess?

         

abbas999

9:26 am on Nov 16, 2007 (gmt 0)

10+ Year Member



I am trying to implement mod_rewrite on my website, but for some reason the rewrite rules dont seem to be working. Is there anything wrong with my .htaccess?


php_flag output_buffering on
php_flag safe_mode off
php_flag register_argc_argv on
php_flag register_globals on
php_value session.gc_maxlifetime 14000
php_value max_execution_time 6000
php_value max_input_time 6000
php_value memory_limit 32M

Options +FollowSymLinks
RewriteEngine on
RewriteRule ^rss/new$ /rss.php?type=new [L]
RewriteRule ^rss/comments$ /rss.php?type=comments [L]
RewriteRule ^rss/views$ /rss.php?type=views [L]
RewriteRule ^view/(.*)/(.*)/ /staging/view_video.php?vid=$1 [L,QSA]

RewriteCond %{HTTP_REFERER}!^http://www.example.com [NC]
RewriteRule ^.*$ http://www.example.com/ [R,L]

RewriteRule \.(tpl)$ - [F,NC,L]

<IfModule mod_security.c>
SecFilterEngine Off
SecFilterScanPOST Off
</IfModule>

[edited by: engine at 10:05 am (utc) on Nov. 16, 2007]
[edit reason] examplified [/edit]

phranque

1:39 pm on Nov 16, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



welcome to WebmasterWorld [webmasterworld.com], abbas999!

unfortunately the "dont seem to be working" part of your description doesn't give quite enough detail.
it would be much easier to figure out what is wrong if we knew what you tried to GET or POST and what your results were.

abbas999

4:41 pm on Nov 16, 2007 (gmt 0)

10+ Year Member



Ah...sorry! Thats what happens when you post messages past midnight after a few drinks :p.

What I meant was that any RewriteRules from this .htaccess are not actually rewriting. For example:
RewriteRule ^rss/new$ /rss.php?type=new [L]

When I go to mywebsite.com/rss.php?type=new, everything works fine. When I try mywebsite.com/rss/new, I get a 404. The same for all rewrite rules in the .htaccess.

(Side question: If I make a change to .htacess, is it applied immediately? Or does apache need to restart for the changes to get applied?)

Thanks a lot for the help!

jdMorgan

8:42 pm on Nov 16, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You need to restart the server for changes in httpd.conf, conf.d, or other server-config-level files to take effect. This is because these files are compiled on server restart, rather than being interpreted on a per-HTTP-request basis as is .htaccess. However, changes in .htaccess take effect immediately when the file is uploaded.

Look at your server error log, paying special attention to the filepath this requested URL was resolved to. If the filepath differs from that which you expected, use the mod_rewrite RewriteBase directive as needed to correct it.

Also be sure to completely flush your browser cache before testing any new code in httpd.conf, conf.d, or .htaccess -- Otherwise your browser will likely serve you a cached copy, and no request will be sent to your server (and this includes previously 404ed URLs).

[added] Side comment: Your fifth rule will break badly if an HTTP/1.0 client connects to your server. It will also break badly if even a legitimate visitor connects to your server through caching proxy, for example, all AOL users. This is because in both of these cases, an HTTP Referer header will not be sent to your server, and the result will be that a request for any object on your site will be redirected to the home page. I would recommend reconsidering both the purpose and the implementation of this rule. [/added]

Jim

[edited by: jdMorgan at 8:46 pm (utc) on Nov. 16, 2007]

abbas999

10:52 pm on Nov 16, 2007 (gmt 0)

10+ Year Member



Thanks a lot for the comments Jim.

What I see in my server error logs is:
[Fri Nov 16 16:48:54 2007] [error] [client 65.67.225.71] File does not exist: /home/viddpkcom/public_html/rss/views

(for the rule RewriteRule ^rss/views$ /rss.php?type=views [L])
I guess that means the URL rewriting isn't even happening, right?

Regarding the fifth rewrite rule, yeah...I'll probably just take it out.

Thanks again for looking at this!