Forum Moderators: phranque

Message Too Old, No Replies

Cannot get .htacces to work

         

mkingsle

5:07 pm on Jan 30, 2008 (gmt 0)

10+ Year Member



For the life of me, I cannot get this to work. I have used your code JD, but it's not working for me. Very frustrating. Here's the code I got from another thread, with changes based on my environment...php

Options +FollowSymLinks
RewriteEngine on

#
## Internally rewrite extensionless file requests to .php files ##
#
# If the requested URI does not contain a period in the final path-part
RewriteCond %{REQUEST_URI}!(\.[^./]+)$
# and if it does not exist as a directory
RewriteCond %{REQUEST_FILENAME}!-d
# and if it does not exist as a file
RewriteCond %{REQUEST_FILENAME}!-f
# then add .php to get the actual filename
RewriteRule ^(([^./]+)+)/?$ /$1.php [L]
#
#
## Externally redirect clients directly requesting .php page URIs to extensionless URIs
#
# If client request header contains html file extension
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^.]+)\.php\ HTTP
# externally redirect to extensionless URI
RewriteRule ^([^.]+)\.php$ [mysite.com...] [R=301,L]

What happens: when I go to an example page:
[mysite.com...]

I get a 404 error. You don't have permission to access /product-page/ on this server.

Secondly, it automatically puts a "/" at the end of the url.

Any help is appreciated

jdMorgan

5:33 am on Feb 1, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> I get a 404 error. You don't have permission to access /product-page/ on this server.

An expensive typo, there... I've stared at this for a couple of days now, before finally realizing that that was not a 404-Not Found error, it was a 403-Forbidden error.

That changes the whole scope. Be back later after thinking some more on this, but it's basically a permissions error, and likely due to having directory indexes disabled (not usually a bad thing, by the way).

Jim

mkingsle

6:44 pm on Feb 1, 2008 (gmt 0)

10+ Year Member



Actually Figured it out. I was noticing that pages with my different folders were working. Being a newby that I am, I didn't realize that when you put and index.php within each individual folder, it defaults to the name of the folder. For example:

Folder Name: widgets

index.php within widgets file will have web address of:
[mysite.com...]

What I was doing was putting a file on the main root called widgets.php and then have a folder for all the widget products. Stupid, but I'm a dummy at this sometimes.

**New Problem Though**

Here's my .htaccess file:

AddHandler x-httpd-php5 .php
AddHandler x-httpd-php .php4
RewriteEngine on

# Redirect client requests for /index.php to www.example.com/
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/
RewriteRule ^index\.php$ http://www.example.com/ [R=301,L]
#
# Redirect requests for all resources in non-www domain to canonical www domain
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule (.*) http://www.example.com/$1 [R=301,L]

#
## Internally rewrite extensionless file requests to .php files ##
#
# If the requested URI does not contain a period in the final path-part
RewriteCond %{REQUEST_URI}!(\.[^./]+)$
# and if it does not exist as a directory
RewriteCond %{REQUEST_FILENAME}!-d
# and if it does not exist as a file
RewriteCond %{REQUEST_FILENAME}!-f
# then add .php to get the actual filename
RewriteRule (.*) /$1.php [L]
#
#
## Externally redirect clients directly requesting .php page URIs to extensionless URIs
#
# If client request header contains html file extension
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^.]+\.)+php\ HTTP
# externally redirect to extensionless URI
RewriteRule ^(.+)\.php$ http://www.example.com/$1 [R=301,L]
RewriteRule ^ama/([A-Za-z0-9]+)$ /global/amazon.php?id=$1

Notice the last rule. What I am trying to do is redirect to a file that has an array in it to process. I've used this on other sites and everything works fine. But something is screwed up on this site and gives me an error. When I take out all the code for doing the extensionless stuff, it redirects fine.

Any help on what I'm missing is greatly appreciated. Must be a conflict going on between rules.

Thanks,

Michael

jdMorgan

7:03 pm on Feb 1, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Put your external redirects first, in order from most-specific to least specific, and follow those with your internal rewrites, again in order from most-specific to least-specific. Generally, longest patterns first -- for example, your domain canonicalization redirect should be your last redirect, as it is a 'catch-all' for those URLs with incorrect domain that don't get taken care of by the more-specific preceding rules.

Jim

mkingsle

3:13 pm on Feb 2, 2008 (gmt 0)

10+ Year Member



Hey again:

As you know from previous posts, I'm relatively new to this, so clarification would be greatly appreciated.

I'm still unsure where in my pecking order I should be placing the last rewrite rule. Actually help with the order of all my rules would be great.

.htaccess is like playing with fire :)

Thanks in advance,

Michael