【问题标题】:.htaccess URL redirected, clean url, trailing slash, force www.htaccess URL 重定向,干净的 url,斜杠,强制 www
【发布时间】:2013-06-27 23:24:02
【问题描述】:

因此,我将我的一个域(我们将其称为 domain.com)重定向到我的一个子目录(我们将其称为文件)中,并且我正在尝试实现将减少索引的链接?page= ,强制使用 www,并为所有页面提供尾部斜杠。

目前我有

domain.com/index?page=about 或 domain.com/splash

我想在哪里 www.domain.com/about/ 或 www.domain.com/splash/

这是我目前所拥有的:

RewriteEngine On

RewriteCond %{HTTP:Host} ^(?:www\.)?domain\.com$ 
RewriteCond %{REQUEST_URI} !^/file/ 
RewriteRule ^(.*) file/$1 [NC,L,NS]

ErrorDocument 404 http://domain.com/splash

如果你看不出来,我对 Apache 不太熟悉,哈哈。

【问题讨论】:

    标签: .htaccess web clean-urls trailing-slash


    【解决方案1】:

    我会选择:

    RewriteEngine On
    
    RewriteCond   %{HTTP:Host}        !^www\.domain\.com$
    RewriteRule   ^(.*)$              http://www.domain.com/$1 [L,R=301]
    
    RewriteCond   %{REQUEST_FILENAME} !-f
    RewriteRule   ^([\w\-]+)$         /$1/ [L,R=301]
    
    RewriteCond   %{REQUEST_FILENAME} !-f
    RewriteRule   ^(.*)$              /index.php?page=$1       [L]
    
    ErrorDocument 404                 /splash/
    

    在调试阶段请小心使用302(临时)重定向而不是301(永久)重定向,因为您的浏览器会“记住”永久重定向,而不会考虑您网站的新配置。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-07-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-22
      • 1970-01-01
      • 2012-12-26
      相关资源
      最近更新 更多