.htaccess 中的 Mod 重写?

发布于 2024-12-17 18:55:18 字数 559 浏览 0 评论 0原文

我想实现从 http://www.onbip.com/index-en.htmlhttp://www.onbip 的 301 重定向。 com/

在 htaccess 文件中我有:

  • RewriteRule ^.htaccess$ - [F,L] #403 Forbidden
  • RewriteRule ^inc/ - [F,L]
  • 重写条件%{HTTP_HOST} ^onbip\.com
  • RewriteRule ^(.*)$ http://www.onbip.com/$1 [R=permanent,L]
  • RewriteRule < code>^index-([^\.]+)\.html$ index.php?lang=$1 [L]

我需要标准化默认页面,该页面将是http://www.onbip.com/

怎么办?

I'd like to implement 301 redirection from http://www.onbip.com/index-en.html to http://www.onbip.com/

In htaccess file I have:

  • RewriteRule ^.htaccess$ - [F,L] #403 Forbidden
  • RewriteRule ^inc/ - [F,L]
  • RewriteCond %{HTTP_HOST} ^onbip\.com
  • RewriteRule ^(.*)$ http: //www.onbip.com/$1 [R=permanent,L]
  • RewriteRule ^index-([^\.]+)\.html$ index.php?lang=$1 [L]

I Need to standardize the default page which will be http://www.onbip.com/

How?

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

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

发布评论

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

评论(1

述情 2024-12-24 18:55:18

在您的 httpd.conf 文件中,应该已经有一行禁止访问 .ht* 文件,可能如下所示:

<Files ~ "^\.ht">
    Order allow,deny
    Deny from all
    Satisfy All
</Files>

如果您想冗余,使用 Files 或 FilesMatch 来保护它可能会很好。如果您想为此使用 Rewrite,您可以抛出 404,就好像它不存在一样。

这是目录 /inc 到 404 页面的重定向(不是 mod_rewrite),

位于 http://httpd.apache.org/docs/2.0/mod/mod_alias.html

Redirect 404 /inc

现在重写

参见http://httpd.apache.org/docs/current/mod/mod_rewrite.html

#Set the page (and order of if they are there) to be shown if asked for a directory
#just put index.php if that's all you want
DirectoryIndex index.php index.html

RewriteEngine on

# if not www.onbip.com, then send to http://www.onbip.com
RewriteCond %{HTTP_HOST} !^www\.onbip\.com [NC]
RewriteRule  ^(.*)$ http://www.onbip.com/$1 [R=301,NC,L]

# Now if entered "/index-ab.html" then call "/?lang=ab"
# You might want to see about the regex for proper lang, I put something like "en" or "us-en"
RewriteBase /
RewriteRule ^index-([a-z]{2}(-[a-z]{2})?)\.html$ ?lang=$1 [R=301,NC,L]

最后一个将从服务器调用“/”,如果根据目录索引存在“index.php”,则首先调用“/”。

In your httpd.conf file, there should already be a line to forbid access to .ht* files that will probably look like this:

<Files ~ "^\.ht">
    Order allow,deny
    Deny from all
    Satisfy All
</Files>

If you want to be redundent, using Files or FilesMatch to protect it would probably be good. If you want to use Rewrite for this, you could throw a 404 as though it doesn't exist.

Here is a redirect (not a mod_rewrite) for a directory /inc to a 404 page

This is at http://httpd.apache.org/docs/2.0/mod/mod_alias.html

Redirect 404 /inc

Now for rewrite

see http://httpd.apache.org/docs/current/mod/mod_rewrite.html

#Set the page (and order of if they are there) to be shown if asked for a directory
#just put index.php if that's all you want
DirectoryIndex index.php index.html

RewriteEngine on

# if not www.onbip.com, then send to http://www.onbip.com
RewriteCond %{HTTP_HOST} !^www\.onbip\.com [NC]
RewriteRule  ^(.*)$ http://www.onbip.com/$1 [R=301,NC,L]

# Now if entered "/index-ab.html" then call "/?lang=ab"
# You might want to see about the regex for proper lang, I put something like "en" or "us-en"
RewriteBase /
RewriteRule ^index-([a-z]{2}(-[a-z]{2})?)\.html$ ?lang=$1 [R=301,NC,L]

The last will call "/" from the server which will be "index.php" first if it exists according to directory index.

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