Forum Moderators: phranque
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
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
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
Jim
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