Forum Moderators: phranque

Message Too Old, No Replies

RewriteRule ^contact contact.php [L]

         

Jase

12:33 am on Oct 9, 2008 (gmt 0)

10+ Year Member



All this is in my custom rules in my virtual host

Include "/usr/local/apache/conf/userdata/std/2/user/domain.com/*.conf"

All my rewrite rules work except these in the footer of my site I get 404. They where working but I do not know or remember why they stopped.

RewriteRule ^about about.php [L]
RewriteRule ^contact contact.php [L]
RewriteRule ^help help.php [L]
RewriteRule ^terms terms.php [L]
RewriteRule ^copyright copyright.php [L]
RewriteRule ^policy policy.php [L]

These rules are in the same list of rules as the ones above. These ones Work.

RewriteRule ^main index.php [L]
RewriteRule ^login login.php [L]
RewriteRule ^logout logout.php [L]
RewriteRule ^tags tags.php [L]

At the top before all these is :

<Directory /home/user/public_html>

ErrorDocument 400 /error.php
ErrorDocument 401 /error.php
ErrorDocument 402 /error.php
ErrorDocument 403 /error.php
ErrorDocument 404 /error.php
ErrorDocument 405 /error.php
ErrorDocument 500 /error.php

<FilesMatch "^\.ht">
deny from all
</FilesMatch>

Options -Indexes
Options +FollowSymlinks

<Files ~ "^(.*)\.(inc¦inc\.php¦tpl¦log)$">
deny from all
</Files>

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

RewriteEngine On

RewriteBase /


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

#### Image Hotlink Protection ####
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?domain.com [NC]
RewriteRule \.(jpg¦jpeg¦png¦gif¦bmp)$ - [NC,F,L]

RewriteRule ^language/([^/]*)$ login.php?language=$1 [L]
RewriteRule ^administration/language/([^/]*)$ administration/index.php?language=$1 [L]
RewriteRule ^main index.php [L]
RewriteRule ^login login.php [L]
RewriteRule ^logout logout.php [L]
RewriteRule ^tags tags.php [L]
RewriteRule ^about about.php [L]
RewriteRule ^contact contact.php [L]
RewriteRule ^help help.php [L]
RewriteRule ^terms terms.php [L]
RewriteRule ^copyright copyright.php [L]
RewriteRule ^policy policy.php [L]
RewriteRule ^my_profile my_profile.php [L]
RewriteRule ^adclick/([^/]*)$ fadclick.php?tid=$1 [L]

Any ideas?

jdMorgan

12:50 am on Oct 9, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I don't see any information about what you want these rules to do... What is their purpose?
So, all I can say is that any rule such as
RewriteRule ^abc abc.xyz [L]
will result in an "infinite" loop, because the output URL-path "abc.xyz" matches the pattern "^abc". Therefore, mod_rewrite will behave recursively, looping until the configured maximum internal redirection limit is reached.

If you mean you want to rewrite extensionless files such as example.com/about to example.com/about.php, then the correct pattern (that would prevent a loop) would be "^about$" ... Note the "$" end-anchor.

Also, there are 'generic' solutions to extensionless URLs that would let you avoid having to write a new rule for each extensionless page that you add -- I posted the code some time in the past week here, if you want to try a search.

Jim

Jase

1:14 am on Oct 9, 2008 (gmt 0)

10+ Year Member



It does not cause an infinite loop it works the way it is no problem. It just causes a 404 reason is unknown.

Jase

1:18 am on Oct 9, 2008 (gmt 0)

10+ Year Member



The rules show that when domain.com/contact then it will display contact.php without the extention.

jdMorgan

1:22 am on Oct 9, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



OK, well you can disregard the extra load on your server then, if you don't want to add the end-anchors...

Best of luck,
Jim

Jase

1:38 am on Oct 9, 2008 (gmt 0)

10+ Year Member



My Other rules have the "$" but not those e.g. Any reason for that?

#### OUTBOX: messages, delete, paging ####
RewriteRule ^outbox/block/([^/]*)$ outbox.php?action=block&mid=$1 [L]
RewriteRule ^outbox/unblock/([^/]*)$ outbox.php?action=unblock&mid=$1 [L]
RewriteRule ^outbox/page([^/]*)$ outbox.php?page=$1 [L]
RewriteRule ^outbox/delete/([^/]*)$ outbox.php?action=delete&mid=$1 [L]
RewriteRule ^outbox/([^/]*)$ message.php?type=outbox&mid=$1 [L]
RewriteRule ^outbox/sort/([^/]*)$ outbox.php?timesort=$1 [L]
RewriteRule ^outbox/sort/([^/]*)/page([^/]*)$ outbox.php?timesort=$1&page=$2 [L]
RewriteRule ^outbox outbox.php [L]
RewriteRule ^compose compose.php [L]

Jase

1:40 am on Oct 9, 2008 (gmt 0)

10+ Year Member



Obviously you can not have a general rule as you have dynamic extensions involved I know thats why each one is done individually but why they did not place an $ on the regular redirect and place some on the dynamic ones I don't know.

jdMorgan

2:38 am on Oct 9, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well, you *can* have a general rule, as long as you put all the exceptions first, such as your outbox/function rules, and the other rules where the destination filepath is not equal to the requested URL plus a .php extension. One rule could replace at least 13 rules that I count above.

I posted this example several times previously:


## Internally rewrite extensionless requested URLs to existing .php files
# If no filetype extension on requested URL-path
RewriteCond $1 !\.[a-z0-9]+$ [NC]
# And if URL-path plus .php extension exists as a file
RewriteCond %{REQUEST_FILENAME}.php -f
# Internally rewrite to file with extension
RewriteRule ^(.+)$ /$1.php [L]

Anyway, that's for later if you want to reduce the number of current and future extensionless-URL-to-filepath rewrite rules.

I have no idea why someone else writes code the way they do, but you should end-anchor those unanchored extensionless URL-path patterns now as a matter of best-practice. I see little point in continuing to try to debug any specific problem until that is corrected because under normal circumstances, that kind of error leads to an internal redirection loop and there is no indication of any reason that your server might be an exception.

Completely flush your browser cache before testing any newly-uploaded code.

Jim

g1smd

3:06 am on Oct 9, 2008 (gmt 0)

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



Your non-www to www 301 redirect should be placed before *all* of the rewrites.

Where it is now, will cause issues for some non-www URL requests.

Jase

4:04 am on Oct 9, 2008 (gmt 0)

10+ Year Member



It is before all of the rewrites am I missing something. It is right after

RewriteEngine On

RewriteBase /

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

#### Image Hotlink Protection ####
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?domain.com [NC]
RewriteRule \.(jpg¦jpeg¦png¦gif¦bmp)$ - [NC,F,L]

Jase

4:41 am on Oct 9, 2008 (gmt 0)

10+ Year Member



How does apache look at this

## Internally rewrite extensionless requested URLs to existing .php files
# If no filetype extension on requested URL-path
RewriteCond $1 !\.[a-z0-9]+$ [NC]
# And if URL-path plus .php extension exists as a file
RewriteCond %{REQUEST_FILENAME}.php -f
# Internally rewrite to file with extension
RewriteRule ^(.+)$ /$1.php [L]

or this

RewriteRule ^main index.php [L]
RewriteRule ^login login.php [L]
RewriteRule ^logout logout.php [L]

Which one would be better for server load?

The second one I'm guessing Apache gets the page request then reads the relevant rule if it exists then outputs page. The first one Apache always checks no matter what the request causing more load.

g1smd

8:32 am on Oct 9, 2008 (gmt 0)

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



The 301 redirect is half way down the list.

The first 10 items, at the very top of the list, are rewrites.

Or, am I missing something?