giovannipds
giovannipds

Reputation: 3469

How to prevent two links show the same content with .htaccess?

I have this case:

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.

Upvotes: 1

Views: 71

Answers (1)

Jon Lin
Jon Lin

Reputation: 143906

Put these in your htaccess file in your document root:

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

Upvotes: 1

Related Questions