mod_rewrite problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mjseaden
Forum Contributor
Posts: 458
Joined: Wed Mar 17, 2004 5:49 am

mod_rewrite problem

Post by mjseaden »

Dear All

I've decided to approach rewriting URLs in a different format. Previously, I was renaming my scripts 'script.php' to just 'script', and using <Files...> ForceType <filename> .. </Files> to treat these extensionless scripts as PHP scripts.

However, for some reason on my shared hosting account this changed the permissions of file transactions carried out by my scripts to the username and group of the base server, rather than the username and group specific to my shared hosting account. This meant that, even though my scripts were run on my server, I was not able to manage files uploaded by my PHP scripts using FTP, or any other method, as my server was giving me denial of permissions errors.

I tried using 'AddHandler cgi-script .', where '.' was used to denote extensionless files, however this did not work. Therefore, I was stuck.

Now I've had a look at my server's phpinfo() and found that the mod_rewrite module is enabled. This is great, and a potential solution to my problem, as I can now keep my scripts called 'script.php' but rewrite the URL without the '.php' extension.

What's less great is that I am a mod_rewrite novice. I have a number of scripts of various names on my server, and I've used the following directives in my .htaccess file:

<IfModule mod_rewrite.c>
Options FollowSymlinks
RewriteEngine On
RewriteRule admin* admin.php
RewriteRule send* send.php
RewriteRule faq* faq.php
RewriteRule index* index.php
RewriteRule print* print.php
RewriteRule show* show.php
RewriteRule terms* terms.php
RewriteRule search* search.php
RewriteRule privacy* privacy.php
RewriteRule property* property.php
</IfModule>

What I've assumed is that if I put 'http://mydomain.com/admin' into the address bar of my internet browser, that this will automatically redirect it to 'http://mydomain.com/admin.php'.

Firstly, I don't know that's absolutely correct. Secondly, I am getting Apache reporting the error:

Code: Select all

Forbidden
You don't have permission to access /index.php on this server.

Apache/1.3.27 Server at mydomain.com Port 80
When I type 'http://mydomain.com/index' into the address bar. So I assume then that it is correctly redirecting to index.php when I type 'index'.

However, can anyone explain what is causing this problem and how it is overcome? My web hosting company didn't seem to be particularly helpful on this issue.

Many thanks

Mark
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

not quite sure on this, since I have little to no experience with the rewrite engine..

have you tried:

Code: Select all

RewriteRule /(index|admin|send|faq|print|show|terms|search|privacy|property)(.*) /$1.php$2 &#1111;R]
Post Reply