1

I have this case:

  • /css/ <-- a folder
  • /css/something.css <-- a file

If the user accesses the folder (/css/), I want that Apache returns the file. If the user tries to access the file directly, (/css/something.css), I want that he be redirected to the folder.

How can I do this without getting a loop? I've read a lot but I couldn't figure it out applying two rules, it always returns a loop. Note: this is my first question on Stack Overflow. Thank you in advance.

4

1 回答 1

1

将这些放在文档根目录中的 htaccess 文件中:

# internal rewrite to serve the file
RewriteRule ^css/$ /css/something.css [L]

# check if the actual request was for the file, then redirect
RewriteCond %{THE_REQUEST} ^(GET|POST)\ /css/something.css
RewriteRule ^css/something.css$ /css/ [R=301,L]
于 2012-07-05T22:45:03.540 回答