htaccess rules differs in local and live server

一世执手 提交于 2019-12-07 07:57:24
Tim Stone

Your comment to JapanPro's answer suggests to me that your site is indeed in a subdirectory on your local server, in which case the likely reason that it doesn't work correctly (based on this and your other question) is because URL structure is different than your live server (it lives at the root there, but not in your local environment).

To fix this, you need to configure Apache to use a name-based virtual host, then add an entry in your hosts file that corresponds to the name you chose. Then you will use that domain name to access your site, and because the URL structure will be consistent with your live site, it should work correctly.

Example:

C:\Windows\System32\drivers\etc\hosts

127.0.0.1 domain.local

httpd.conf

<VirtualHost *:80>
    ServerName domain.local

    DocumentRoot "C:\wampdir\htdocs\mydomain"

    <Directory "C:\wampdir\htdocs\mydomain">
        Options Indexes FollowSymLinks Includes
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

Edit: Here's a more in-depth description of setting up virtual hosts and editing in a new host entry that should hopefully explain this process better than I have.

what you are using in local xampp, wamp or any other , you may need to enable htaccess

i m considering u are using xampp or recommend to use it.

How to enable or use .htaccess on Apache Web Servers in Windows:

Using a text editor, open the httpd.conf file. In XAMPP, this file is found in the \apache\conf directory
Locate the following line of code:
#LoadModule rewrite_module modules/mod_rewrite.so

Remove the # from the line as seen below to enable the module:
LoadModule rewrite_module modules/mod_rewrite.so

Save the httpd.conf file and Restart your server
Restart your Apache Server

Depending on the AccessFileName setting, your local Apache installation might use another name, for example _htaccess. Furthermore, make sure that the AllowOverride directive is not set to None.

Further documentation can be found in the .htaccess tutorial.

RewriteCond %{HTTP_HOST} ^mydomain.com [NC]

If the host is [starts with (^)] mydomain.com,

RewriteRule ^(.*)$ http://www.mydomain.com/$1 [L,R=301]  

rewrite it to http ://www.mydomain.com/$1

RewriteCond %{HTTP_HOST} !mydomain.com [NC] 

If the host is not(!) mydomain.com,

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