1

i'm working with a PHP application in an Apache server. I want to use the rewrite php module to transform all the urls links like the following example: www.mysite.com/home.php ---> www.mysite.com/home

The problem is that the module is loading and functioning only for the first rule (home-->home.php), all the others rules are ignored.

I can't understand where is the problem

This is my .htaccess file

<IfModule mod_rewrite.c>
Options +FollowSymlinks
# Options +SymLinksIfOwnerMatch
Options +FollowSymlinks
RewriteEngine On
# RewriteBase /
</IfModule>



# Option 1:
# Rewrite "www.example.com -> example.com".
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]
</IfModule>



RewriteRule      ^home$                          index.php                    [NC,L]
RewriteRule      ^ga$                    ga.php                         [NC,L]
RewriteRule          ^info                       info.php                                       [NC,L]
RewriteRule      ^ecosoc                     ecosoc.php                   [NC,L]
RewriteRule      ^sc                         sc.php                       [NC,L]
RewriteRule      ^icj                        icj.php                      [NC,L]
#RewriteRule     ^gallery$                  gallery.php                  [NC,L]
#RewriteRule     ^archive$                  archive/index.php            [NC,L]
RewriteRule      ^contact$                   contact.php                  [NC,L]


#RewriteRule      ^login$                    login.php                    [NC,L]


RewriteRule      ^registration$             registration.php                  [NC,L]
RewriteRule      ^delegate$                 delegate.php                      [NC,L]
RewriteRule      ^delegate/success$         delegate.php?result=success       [NC,L]
RewriteRule      ^delegate/error$           delegate.php?result=error         [NC,L]

RewriteRule      ^iscrizioni/confirm/([a-z]*)$    confirm_registration.php?action=$1  [NC,L]
RewriteRule      ^iscrizioni/confirm/user/(.*)$   confirm_registration.php?action=confirm&code=$1  [NC,L]



#RewriteRule      ^course$                   course.php?e=error               [NC,L]
RewriteRule      ^staff$                    staff.php                        [NC,L]
RewriteRule      ^staff/success$            staff.php?result=success         [NC,L]

#RewriteRule      ^schoolarea/$              http://school.rimun.com          [NC,L]

and this is my vhost .conf file

#
# public-website
#

<Directory  /var/www/public-website>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride all

    Require all granted
</Directory>

<VirtualHost *:80>
    DirectoryIndex index.php  #settare al nome file da aprire all'accesso al sito
    ServerName sociall.local
    ServerAdmin croce.1546488@studenti.uniroma1.it
    DocumentRoot /var/www/public-website/

    ErrorLog /var/www/public-website/error.log
    #CustomLog /var/www/html/sociall/log/access.log combined
</VirtualHost>

Thank you in advice for your support.

1 Answers1

0

You need to clean up your htaccess file.

Create a copy of your htaccess file.

Remove all content in the original file.

Add this as a starter

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
Options +FollowSymlinks

RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]

RewriteRule ^home$ index.php [NC,L]
RewriteRule ^ga$ ga.php [NC,L]
</IfModule>

Now redirect to home and ga should work. If they don't work you localized the problem to this code. Try to fix it. When you fix this code, you can append the rest of the rewrite rules one by one (not all at once).

SergeyAn
  • 754
  • 6
  • 9
  • Is it possible to post the url of your website here? Have you tried the exact code that I posted? – SergeyAn Sep 08 '15 at 08:48
  • I have done exactly as you show to me. I want to precise that the module works properly on the web server. It doesn't on my localhost server. BTW the website is rimun.com. It also works properly on a Macbook with MAMP. It only doesn't works on my linux PC with Apache server. – Lorenzo Gallucci Sep 08 '15 at 10:54