ggkmath
ggkmath

Reputation: 4246

simple Apache RewriteCond and RewriteRule issue

I'm trying to follow https://github.com/crwilliams/diary-user-interface/wiki/cachebusting

If I set my HTML code to:

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

and add to .htaccess:

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

I see "Page not found" error as the browser goes to: https://www.mycompany.com/myDir/myFile.2013103000.html

Any idea what could be happening?

What can I do to trouble shoot?

Sitting at the webpage with the link, if I change .htaccess to this:

<IfModule mod_rewrite.c>
   RewriteEngine on
   RewriteRule ^(.+) https://www.mycompany.com/myDir/myFile.html [L]  
</IfModule>

and then click the link it works (but obviously this just for troubleshooting).

UPDATE

Here's the complete .htaccess file in case something following the above can be identified as the problem:

# 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>

Upvotes: 1

Views: 218

Answers (1)

Phil
Phil

Reputation: 165059

I'd remove that last block and put it in a separate .htaccess file in your /home directory, eg

# /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>

Upvotes: 1

Related Questions