我应该在哪里放置我的301重定向的htaccess文件?

时间:2023-01-13 23:11:48

We are switching from Cart32 (powered by ASP.Net) to OpenCart (powered by php). We have links all over the site pointing to the older cart location. We also have an older cart on our site consisting of a bunch of html pages that I used a META redirect on, but want to switch to a 301 redirect for these pages as well.

我们正在从Cart32(由ASP.Net提供支持)切换到OpenCart(由php提供支持)。我们在整个网站上都有指向旧购物车位置的链接。我们的网站上还有一个较旧的购物车,其中包含一些我使用META重定向的html页面,但是也希望切换到这些页面的301重定向。

I want to redirect these pages:

我想重定向这些页面:

  • /cgi-bin/cart32.exe/TLDM-store

  • /products/OrderForm/Default.htm

to

  • /store/

I got this code for the first one:

我得到了第一个代码:

# Permanent URL redirect - generated by www.rapidtables.com
Redirect 301 /cgi-bin/cart32.exe/TLDM-store http://www.tldm.org/store/

And this for the second one:

这是第二个:

# Permanent URL redirect - generated by www.rapidtables.com
Redirect 301 /products/OrderForm/Default.htm http://www.tldm.org/store/

Where should I put these htaccess files? In the root directory or in the /cgi-bin/ and /products/ folders respectively.

我应该把这些htaccess文件放在哪里?分别位于根目录或/ cgi-bin /和/ products /文件夹中。

1 个解决方案

#1


From the documentation :

从文档:

A [htaccess] file, containing one or more configuration directives, is placed in a particular document directory, and the directives apply to that directory, and all subdirectories thereof.

包含一个或多个配置指令的[htaccess]文件放在特定的文档目录中,并且指令适用于该目录及其所有子目录。

Both solutions will work (in the root directory vs in sub directories), the difference is a matter of taste. If you have only two rules I would put them in the same file at the root folder, if you have more rules I would probably split them.

两种解决方案都可以工作(在根目录和子目录中),区别在于品味。如果你只有两个规则我会把它们放在根文件夹的同一个文件中,如果你有更多的规则,我可能会将它们分开。

A third (better) solution, if you have access to the server configuration, is to put the rewrite rules there :

如果您有权访问服务器配置,第三个(更好的)解决方案是将重写规则放在那里:

In general, you should only use .htaccess files when you don't have access to the main server configuration file. [...] Likewise, mod_rewrite directives work better, in many respects, in the main server configuration.

通常,只有在无法访问主服务器配置文件时才应使用.htaccess文件。 [...]同样,mod_rewrite指令在许多方面在主服务器配置中更好地工作。

Don't forget to enable and check the debug logs for the rewrite module say (RewriteLog and RewriteLogLevel for apache 2.2, LogLevel for apache 2.4) if you have troubles with rules that don't apply.

如果您遇到不适用的规则问题,请不要忘记启用并检查重写模块的调试日志(例如,针对apache 2.2的RewriteLog和RewriteLogLevel,针对apache 2.4的LogLevel)。

#1


From the documentation :

从文档:

A [htaccess] file, containing one or more configuration directives, is placed in a particular document directory, and the directives apply to that directory, and all subdirectories thereof.

包含一个或多个配置指令的[htaccess]文件放在特定的文档目录中,并且指令适用于该目录及其所有子目录。

Both solutions will work (in the root directory vs in sub directories), the difference is a matter of taste. If you have only two rules I would put them in the same file at the root folder, if you have more rules I would probably split them.

两种解决方案都可以工作(在根目录和子目录中),区别在于品味。如果你只有两个规则我会把它们放在根文件夹的同一个文件中,如果你有更多的规则,我可能会将它们分开。

A third (better) solution, if you have access to the server configuration, is to put the rewrite rules there :

如果您有权访问服务器配置,第三个(更好的)解决方案是将重写规则放在那里:

In general, you should only use .htaccess files when you don't have access to the main server configuration file. [...] Likewise, mod_rewrite directives work better, in many respects, in the main server configuration.

通常,只有在无法访问主服务器配置文件时才应使用.htaccess文件。 [...]同样,mod_rewrite指令在许多方面在主服务器配置中更好地工作。

Don't forget to enable and check the debug logs for the rewrite module say (RewriteLog and RewriteLogLevel for apache 2.2, LogLevel for apache 2.4) if you have troubles with rules that don't apply.

如果您遇到不适用的规则问题,请不要忘记启用并检查重写模块的调试日志(例如,针对apache 2.2的RewriteLog和RewriteLogLevel,针对apache 2.4的LogLevel)。