-3

I am creating a .htaccess file in the path of my site var/www/mysite/ to remove my files the ".php", but does not work

# Apache Rewrite Rules
 <IfModule mod_rewrite.c>
 Options +FollowSymLinks
 RewriteEngine On
 RewriteBase /

# Add trailing slash to url
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/|#(.*))$
RewriteRule ^(.*)$ $1/ [R=301,L]

# Remove .php-extension from url
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^([^\.]+)/$ $1.php 

# End of Apache Rewrite Rules
</IfModule>

It is the first time I do this and if I'm not doing well, or whether this in the right place, so I come to you.

hateful
  • 141
  • 2
  • 13
  • Check the RewriteLog. After unconditionally always appending a trailing slash, the `RewriteCond /input/path/.php -f` will never match. – mario Apr 28 '16 at 20:50
  • @anubhava For example, I have about.php, redirect about but can not find., But if I redirect to about.php works. – hateful Apr 28 '16 at 21:02
  • www.mysite.com/about and failed, but www.mysite.com/about.php its works! @anubhava – hateful Apr 28 '16 at 21:11
  • 1
    Possible duplicate of [How to remove file extension from website address?](http://stackoverflow.com/questions/6534904/how-to-remove-file-extension-from-website-address) – Reto Apr 28 '16 at 21:14
  • No, it does not work for me, I .htaccess but I still can see my other pages. – hateful Apr 28 '16 at 21:24
  • 500 error is generated, nothing happens D:, not that I'll be doing wrong! – hateful Apr 28 '16 at 21:30

1 Answers1

0

Try this code in site root .htaccess:

Options +FollowSymLinks
RewriteEngine On

# Add trailing slash to url that is not a file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*?[^/])$ %{REQUEST_URI}/ [L,R=302,NE]

# Add .php extension from urls internally
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php 
anubhava
  • 761,203
  • 64
  • 569
  • 643
  • I just set up my ubuntu server and I think I have not properly configured Apache, because htaccess that you give me if they work on another server that I have, but driving me crazy lol the conf apache – hateful Apr 28 '16 at 21:36