Apache php,mod_rewrite似乎无法正常工作

时间:2015-09-07 12:32:43

标签: php apache .htaccess mod-rewrite virtualhost

我正在使用Apache服务器中的PHP应用程序。我想使用重写php模块来转换所有url链接,如下例所示:www.mysite.com/home.php ---> www.mysite.com/home

问题是模块正在加载并仅为第一个规则(home - > home.php)运行,所有其他规则都被忽略。

我无法理解问题在哪里

这是我的.htaccess文件

<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]

这是我的vhost .conf文件

#
# 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>

感谢您的支持。

1 个答案:

答案 0 :(得分:0)

您需要清理htaccess文件。

创建htaccess文件的副本。

删除原始文件中的所有内容。

将其添加为启动器

<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>

现在重定向到家,ga应该有效。如果他们不工作,您将问题本地化为此代码。尝试解决它。修复此代码后,您可以逐个附加其余的重写规则(不是一次性完成)。