0

I have an .htaccess file in my directory where I'd like to change about-us.php to /about-us/ and I have used mod_mod_rewrite generator to do so however either I get 500 internal server errors or it doesn't work. So I checked my apache and its already enabled as default - I also have confirmed this is enabled using

        /usr/local/apache/bin/httpd -l | grep rewrite

and I get

       mod_rewrite.c

but this is it, my server is centos 6

I really don't know what else I need to do, do you guys have any idea? code below is another try but even this doesn't work fine

        RewriteEngine On

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

Many thanks in advance

2 Answers2

0

http://httpd.apache.org:

In general, .htaccess files use the same syntax as the main configuration files. What you can put in these files is determined by the AllowOverride directive. This directive specifies, in categories, what directives will be honored if they are found in a .htaccess file. If a directive is permitted in a .htaccess file, the documentation for that directive will contain an Override section, specifying what value must be in AllowOverride in order for that directive to be permitted.

http://httpd.apache.org/docs/2.2/mod/core.html#allowoverride

<Directory /var/www/>
        AllowOverride All
</Directory>
avarx
  • 509
  • 5
  • 21
0

As @ava points out, make sure your Apache server is set to allow directives at the directory level via htaccess. It appears that your rewrite rule is backwards. You state that you want to redirect from files (about-us.php) to a directories (about-us) but your rule is set up for the opposite.

If you're just rewriting one file, do so explictly.

Rewrite On
# Rewrite specific file (not case sensitive, stop processing rules).
RewriteRule about-us.php about-us [NC,L] 

Or, you can remove .php from all files. The following reverses the answer given here.

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*).php $1 [NC,L]

Also consider where the URLs are in relation to the web root and where your htaccess file is (see RewriteBase). If this is a permanent redirect, you should let bots know with [R=301].

Community
  • 1
  • 1
Chad Kieffer
  • 491
  • 4
  • 8
  • Thank you, yes done that, restarted my apache successfully and used your code, i dont get errors but also it doesn't work – user3473245 Mar 28 '14 at 16:39
  • Where are your files in relation to your web root? Are they at / or in a sub-directory? Try adding RewriteBase / if the former or RewriteBase /path/ if you're in a sub-directory. In either case, your htaccess should be in the web root (/). – Chad Kieffer Mar 28 '14 at 16:47
  • In addition to my previous answer, my .htaccess is located in public_html directory where all website files are housed. – user3473245 Mar 28 '14 at 16:47