Forum Moderators: phranque
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?
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
#### 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]
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]
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
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]
## 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.