htaccess 规则在本地和实时服务器中有所不同

发布于 2024-09-17 01:08:59 字数 1763 浏览 1 评论 0原文

我有 PHP oscommerce 网站,在其中我使用 htaccess 进行 url 重写来隐藏文件名,现在我面临的问题是我的本地服务器无法复制 htaccess ,因为它应该做,它在实时站点中运行完美。

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

已编辑

下面是我正在使用的 htaccess 重写规则,出于安全目的,我已将原始站点名称替换为“mydomain”:

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]

现在问题是这样的:

我有一个链接,如下所示:

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

现在在本地计算机,当我单击此链接时,我将导航到 url,

http://192.168.1.55/about_us.html

而不是应该导航到

http://192.168.1.55/mydomain/about_us.html

根据其域名在实时服务器上可用的预期 url,但在本地我得到页面未找到..

请帮助

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

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]

Now the problem goes like this:

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

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

Please help

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

浅忆 2024-09-24 01:09:00

您在本地 xampp、wamp 或任何其他中使用的内容,您可能需要启用 htaccess

我正在考虑您正在使用 xampp 或建议使用它。

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

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
倾听心声的旋律 2024-09-24 01:09:00

根据 AccessFileName 设置,您的本地 Apache 安装可能会使用另一个名称,例如 _htaccess。
此外,请确保 AllowOverride 指令未设置为没有

更多文档可以在 .htaccess 教程中找到。

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.

勿忘初心 2024-09-24 01:09:00

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

如果主机是[以 (^) 开头] mydomain.com,

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

则将其重写为 http://www.mydomain.com/$1

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

如果主机不是(!)mydomain.com,

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,

以可爱出名 2024-09-24 01:08:59

您对 JapanPro 的回答的评论向我建议您的网站确实位于本地服务器上的子目录中,在这种情况下,它可能无法正常工作的原因(基于此和 你的另一个问题)是因为URL结构与你的实时服务器不同(它位于那里的根目录,但不在你的本地环境中)。

要解决此问题,您需要将 Apache 配置为使用名称-基于虚拟主机,然后在主机文件中添加与您选择的名称相对应的条目。然后,您将使用该域名访问您的网站,并且由于 URL 结构将与您的实时网站一致,因此它应该可以正常工作。

示例:

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>

编辑这里有关于设置虚拟主机和编辑新主机条目的更深入的描述,希望它能比我更好地解释这个过程。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文