leony Posted June 7, 2008 Share Posted June 7, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/109122-mod_rewrite-help-please/ Share on other sites More sharing options...
GingerRobot Posted June 8, 2008 Share Posted June 8, 2008 Checked your error log? Do you have the rewrite_module loaded? Quote Link to comment https://forums.phpfreaks.com/topic/109122-mod_rewrite-help-please/#findComment-560379 Share on other sites More sharing options...
leony Posted June 8, 2008 Author Share Posted June 8, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/109122-mod_rewrite-help-please/#findComment-560490 Share on other sites More sharing options...
GingerRobot Posted June 8, 2008 Share Posted June 8, 2008 I spose i could always try reading the post properly couldn't I? 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? Quote Link to comment https://forums.phpfreaks.com/topic/109122-mod_rewrite-help-please/#findComment-560505 Share on other sites More sharing options...
jamieburchell Posted June 9, 2008 Share Posted June 9, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/109122-mod_rewrite-help-please/#findComment-561063 Share on other sites More sharing options...
leony Posted June 10, 2008 Author Share Posted June 10, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/109122-mod_rewrite-help-please/#findComment-561805 Share on other sites More sharing options...
jamieburchell Posted June 10, 2008 Share Posted June 10, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/109122-mod_rewrite-help-please/#findComment-561871 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.