Jump to content


Photo

modification rewrite doesn't work


  • Please log in to reply
11 replies to this topic

#1 jackmaessen

jackmaessen

    Newbie

  • New Members
  • Pip
  • 6 posts

Posted 08 January 2013 - 07:24 AM

Hello,
I am trying to remove my .php extensions with rewrite_mod.
I use this code in my .htaccess file which is in the webroot:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php

In my apache httpd.conf file, i removed the # sign from the LoadModule

But it is still not working for me
Can anyone tell me why it does not work?

#2 cpd

cpd

    ¬_¬

  • Members
  • PipPipPip
  • 890 posts
  • LocationLondon, UK

Posted 08 January 2013 - 09:55 AM

Have you restarted Apache?

"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it."

"One of my most productive days was throwing away 1000 lines of code."

#3 jackmaessen

jackmaessen

    Newbie

  • New Members
  • Pip
  • 6 posts

Posted 08 January 2013 - 11:02 AM

yes i did restart all services

#4 cpd

cpd

    ¬_¬

  • Members
  • PipPipPip
  • 890 posts
  • LocationLondon, UK

Posted 08 January 2013 - 12:48 PM

Well you need to escape the dot in your second condition.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it."

"One of my most productive days was throwing away 1000 lines of code."

#5 jackmaessen

jackmaessen

    Newbie

  • New Members
  • Pip
  • 6 posts

Posted 08 January 2013 - 01:43 PM

i do not understand what you mean by escape

#6 cpd

cpd

    ¬_¬

  • Members
  • PipPipPip
  • 890 posts
  • LocationLondon, UK

Posted 08 January 2013 - 01:54 PM

You have special characters in most if not all computer languages that represent something. In this case a dot/period/. - in the second condition - matches the requested file name, followed by some character, followed by "php".

E.g. "myfilexphp", "myfile4php", "myfile:php" are all valid but technically incorrect.

To ensure it matches a dot only you must escape the special character; this applies to every special character. This can be done by using a backslash although it may be another character in some languages (I'm yet to see one where its not a backslash). So your condition should read:

RewriteCond %{REQUEST_FILENAME}\.php -f

Edited by cpd, 08 January 2013 - 01:54 PM.

"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it."

"One of my most productive days was throwing away 1000 lines of code."

#7 jackmaessen

jackmaessen

    Newbie

  • New Members
  • Pip
  • 6 posts

Posted 08 January 2013 - 02:04 PM

that also doesnt work

my code:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php

I tried also a space between } and \, but gives me a 500 server error
RewriteCond %{REQUEST_FILENAME} \.php -f

i have tried so many things, but nothing seems to work

Edited by jackmaessen, 08 January 2013 - 02:10 PM.


#8 cpd

cpd

    ¬_¬

  • Members
  • PipPipPip
  • 890 posts
  • LocationLondon, UK

Posted 08 January 2013 - 02:31 PM

Are you running this on WAMP or something? It sounds like mod_rewrite isn't enabled.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it."

"One of my most productive days was throwing away 1000 lines of code."

#9 jackmaessen

jackmaessen

    Newbie

  • New Members
  • Pip
  • 6 posts

Posted 08 January 2013 - 02:46 PM

yes i am running it on WAMP, but in the httpd.config file, i removed the # sign from the line:
LoadModule rewrite_module modules/mod_rewrite.so
So modification rewrite must be enabled

Edited by jackmaessen, 08 January 2013 - 02:47 PM.


#10 cpd

cpd

    ¬_¬

  • Members
  • PipPipPip
  • 890 posts
  • LocationLondon, UK

Posted 08 January 2013 - 02:52 PM

Click WAMP -> Apache -> Apache Modules and see if mod_rewrite is enabled.

Edit: it should be called rewrite_module.

Edited by cpd, 08 January 2013 - 02:53 PM.

"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it."

"One of my most productive days was throwing away 1000 lines of code."

#11 jackmaessen

jackmaessen

    Newbie

  • New Members
  • Pip
  • 6 posts

Posted 08 January 2013 - 04:22 PM

yes it is enabled; there is a V sign for the line

#12 cpd

cpd

    ¬_¬

  • Members
  • PipPipPip
  • 890 posts
  • LocationLondon, UK

Posted 08 January 2013 - 06:27 PM

Have you tried closing and restarting WAMP altogether to be absolutely sure?
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it."

"One of my most productive days was throwing away 1000 lines of code."




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com