.htaccess not working on live site but working on localhost?

人走茶凉 提交于 2019-12-12 02:03:10

问题


I am using ExpressionEngine and want to remove index.php from my URL's. I have this .htaccess file saved in the root folder. It works perfectly on localhost but when I upload it to the server it doesn't work. The correct URL appears in the address bar but the page stays on homepage. Any tips?

<IfModule mod_rewrite.c>
    # Enable Rewrite Engine
    # ------------------------------
    RewriteEngine On
    RewriteBase /
    # Redirect index.php Requests
    # ------------------------------
    RewriteCond %{THE_REQUEST} ^[^/]*/index\.php [NC]
    RewriteCond %{THE_REQUEST} ^GET
    RewriteRule ^index\.php(.+) $1 [R=301,L]
    # Standard ExpressionEngine Rewrite
    # ------------------------------
    RewriteCond $1 !\.(css|js|gif|jpe?g|png) [NC]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /index.php/$1 [L]
</IfModule>

回答1:


Make sure your AllowOverride Directive in Apache is configured to allow .htaccess files and your server has mod_rewrite installed and active.

On Mac OS X, you'll find this file at /etc/apache2/httpd.conf. Look for the <Directory> Directive and change it to be:

<Directory />
    Options FollowSymLinks
    AllowOverride All
    Order deny,allow
</Directory>

You'll need to restart Apache so it can read the new configuration:

sudo /usr/sbin/apachectl restart

If you'd prefer to use a GUI to restart Apache, go to Apple > System Preferences > Sharing and toggle the checkbox next to the Web Sharing service.

If you're using Windows or any flavor of Linux, the same approach applies, but the Apache configuration may be in a different place, especially if you're using WAMP or MAMP.


Also, for reference, the "officially supported method" by EllisLab for Removing index.php from ExpressionEngine URLs is the following:

<IfModule mod_rewrite.c>
    RewriteEngine On
    # Removes index.php
    RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /index.php/$1 [L]
    # If 404s, "No Input File" or every URL returns the same thing
    # make it /index.php?/$1 above (add the question mark)
</IfModule>


来源:https://stackoverflow.com/questions/6847625/htaccess-not-working-on-live-site-but-working-on-localhost

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!