htaccess的规则在不同地方和活的服务器规则、不同、服务器、地方

2023-09-02 01:11:03 作者:轰炸僚机

喜 我有PHP自从网站,在我所用htaccess的URL重写隐藏文件名,现在我面临的问题是,我的本地服务器无法复制htaccess的,因为它应该做的事,这是工作完美的直播现场..

Hi I have PHP oscommerce website, in which I have used htaccess for url rewriting to hide file names, now the problem i am facing is that my local server cannot replicate the htaccess as it should be doing, It is working perfect in live site..

能否有人建议可能是什么原因?

Can some suggest what could be the reason?

EDITED

下面是我使用htaccess的重写规则,我已经取代我原来的网站名称为MYDOMAIN为安全起见:

Below Is the htaccess rewrite rule i am using, i have replaced my original sites name with "mydomain" for security purpose:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^mydomain.com [NC] 
RewriteRule ^(.*)$ http://www.mydomain.com/$1 [L,R=301]  

#INDEX PAGE
#----------
RewriteRule http://www.mydomain.com/index.html  http://www.mydomain.com/ [R]
RewriteRule http://www.mydomain.com/index.php  http://www.mydomain.com/ [R]
RewriteRule ^index.html index.php [NC]


#STATIC PAGES
#------------
RewriteRule ^about-us.html information.php?info_id=1 [NC]
RewriteRule ^faqs.html information.php?info_id=8 [NC]
RewriteRule ^contact-us.html contact_us.php?info_id=9 [NC]
RewriteRule ^terms-and-conditions.html information.php?info_id=10 [NC]
RewriteRule ^privacy-policy.html information.php?info_id=3 [NC]

#RewriteRule ^we-design-your-banner-free.html information.php?info_id=11 [NC]
RewriteRule ^vinyl-banner-samples.html vinyl_banner_sample.php [NC]
RewriteRule ^art-specifications.html art_specification.php [NC]
RewriteRule ^sitemap.html sitemap.php [NC]


#checkout - my account pages
#---------------------------
#RewriteRule ^account.html account.php?$1 [NC]
#RewriteRule ^checkout.html checkout.php?$1 [NC]

现在的问题是这样的:

我有一个链接,是这样的:

I have a link which is like:

<a href="/about_us.html" title="About Us" class="footertext_link">About Us</a>

现在在本地机器上,当我点击这个链接,我浏览到网址

Now in local machine when i click this link I am navigated to url

http://192.168.1.55/about_us.html

而应该导航到

rather it should be navigated to

http://192.168.1.55/mydomain/about_us.html

预计URL可现场服务器根据其域名,但在当地我得到找不到网页。

expected url is available on live server according to its domain name, but on local I get Page not found..

请帮忙

推荐答案

您注释JapanPro's回答建议,我认为你的网站确实是一个子目录中的本地服务器上,在这种情况下,可能的原因,它不能正常工作(在此基础上与的您的其他问题)是因为URL的结构比你活的服务器不同(它生活在那里扎根,但不是在你的本地环境)。

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

要解决这个问题,你需要配置Apache 使用基于域名的虚拟主机,然后添加在你的hosts文件对应于您选择的名称的项。然后,你将使用域名来访问您的网站,因为URL结构将与您直播的网站保持一致,它应该正常工作。

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.

例如:

C: WINDOWS SYSTEM32 DRIVERS 等主机


127.0.0.1 domain.local

的httpd.conf

<VirtualHost *:80>
    ServerName domain.local

    DocumentRoot "C:wampdirhtdocsmydomain"

    <Directory "C:wampdirhtdocsmydomain">
        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.