Jump to content

Recommended Posts

Hi,

I have got a problem and cannot find a solution.

 

I want to get rid of PHP extensions on my website (hosted by 1and1 - Apache servers)

 

A basic rule is as follows

 

RewriteEngine on
RewriteRule ^phones /phones.php

 

But I get internal server error 500.

 

If the rule is as:

 

RewriteEngine on
RewriteRule ^phones-nokia /phones.php

The rule works! Whenever the new URL name is different than the old page name, it works. (etc. ^cars /cars.php does not work but ^cars-honda /cars.php works)

 

Because I cannot find a solution in this problem, I cannot go ahead and write more complicated rules.

 

A test:

 

Created a page called write.php with only the following line:

<?php echo $_SERVER['QUERY_STRING'] ?> 

HTACCESS file is in: domain.com/.htaccess

 

Tried the following rule:

RewriteEngine On
RewriteRule ^(.*)$ /write.php?$1 [L]

Normally whatever I type in domain.com/anything should display "anything". But I get 500 error.

 

So can someone please tell me what am I doing wrong?

 

Thanks.

Link to comment
https://forums.phpfreaks.com/topic/109122-mod_rewrite-help-please/
Share on other sites

Checked your error log? Do you have the rewrite_module loaded?

 

I cannot check the error log because 1and1 does not allow. If the module is not loaded, how can this works:

RewriteEngine on
RewriteRule ^phones-nokia /phones.php

And I get error 500 for the following?

RewriteEngine on
RewriteRule ^phones /phones.php

 

If you can explain what might be possible reasons, I will contact them and ask.

I spose i could always try reading the post properly couldn't I? :P

 

Well, i'm not mod_rewrite expert, but i would imagine that the problem is your pattern is matched by phones.php so you have an infinite loop. I wonder if using the L flag would prevent that?

Hi

 

I notice on your examples you are missing the end dollar. I am pretty sure this is your issue.

 

RewriteRule ^phones /phones.php

I would make:

RewriteRule ^phones$ /phones.php

or better:

RewriteRule ^phones/?$ /phones.php

 

I've not managed to get: RewriteRule ^(.*)$ /write.php?$1 [L] to work either. I have no idea why this is. I ended up having to use:

([a-zA-Z0-9-/]+) which did what I needed.

Hi

 

I notice on your examples you are missing the end dollar. I am pretty sure this is your issue.

 

RewriteRule ^phones /phones.php ---not working on 1and1 but works on another server

I would make:

RewriteRule ^phones$ /phones.php---not working on 1and1 but works on another server

or better:

RewriteRule ^phones/?$ /phones.php---not working on 1and1 but works on another server

 

RewriteRule ^phones-1and1-sucks/?$ /phones.php---works on 1and1 and on another server!

 

I've not managed to get: RewriteRule ^(.*)$ /write.php?$1 [L] to work either. I have no idea why this is. I ended up having to use:

([a-zA-Z0-9-/]+) which did what I needed.

 

Is there any special mod_rewrite method for 1and1 that I am not aware of? I dont wanna waste my time asking them as they have no idea what they are doing.

I doubt they will know. What version of Apache is running on your server vs the version that you have managed to get working.

 

I am running Apache 2.2.6 on Windows and basically all the problems are resolved by adding an end dollar for the string terminator.

 

I get:

 

RewriteRule ^register /register.php -- 500 server error

RewriteRule ^register /xregister.php -- rule works (sort of see below)

RewriteRule ^register$ /register.php -- rule works

 

You'll find without the end of string terminator all sorts of unexpected stuff happens like the url /registerxyz will still resolve to /xregister.php.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.