简单的Apache RewriteCond和RewriteRule问题

时间:2013-10-30 23:51:21

标签: apache mod-rewrite

我正在尝试关注https://github.com/crwilliams/diary-user-interface/wiki/cachebusting

如果我将HTML代码设置为:

  href="/myDir/myFile.2013103000.html"

并添加到.htaccess:

<IfModule mod_rewrite.c>
  RewriteEngine on
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.+)\.(\d+)\.(html)$ $1.$3 [L]
</IfModule>

我在浏览器转到https://www.mycompany.com/myDir/myFile.2013103000.html

时看到“找不到网页”错误

知道会发生什么事吗?

我可以做些什么来解决问题?

如果我将.htaccess更改为:

,请坐在带有链接的网页上
<IfModule mod_rewrite.c>
   RewriteEngine on
   RewriteRule ^(.+) https://www.mycompany.com/myDir/myFile.html [L]  
</IfModule>

然后点击它可以使用的链接(但显然这仅用于故障排除)。

更新

这是完整的.htaccess文件,以防上述内容可以被识别为问题:

# attempt to implement version control with cachebusting
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.+)\.(\d+)\.(html)$ $1.$3 [L]
</IfModule>

# Pruning irrelevant parts (Phil)

# force SSL and www
RewriteCond %{HTTP_HOST} ^mycompany\.com$ [OR]
RewriteCond %{HTTPS} !on
RewriteRule ^(.*)$ https://www.mycompany.com/$1 [R=301,L]

# Redirect index.html to a specific subfolder;
Redirect permanent /index.html https://www.mycompany.com/home/

# enable pretty url
<IfModule mod_rewrite.c>
    RewriteBase /home/
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME}/index.html !-f
    RewriteCond %{REQUEST_FILENAME}/index.php !-f
    RewriteRule . index.php [L]
</IfModule>

1 个答案:

答案 0 :(得分:1)

我会移除最后一个块并将其放在.htaccess目录中的单独/home文件中,例如

# /home/.htaccess

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    # not sure about the next 3 lines though
    RewriteCond %{REQUEST_FILENAME}/index.html !-f
    RewriteCond %{REQUEST_FILENAME}/index.php !-f
    RewriteRule . index.php [L]
</IfModule>