Reputation: 319
Common problem, but too complicated for me.
Here are the requirements I am trying to meet:
I searched a lot and tried a lot of rewrite conditions and rules, but htaccess+regex is just from another planet for me. :/ Sorry if this is a duplicate…
Upvotes: 1
Views: 485
Reputation: 143906
These would be in the htaccess file in your document root. Turn on the rewrite engine
RewriteEngine On
For 1 and 2: redirect to "www" if root request or request for /c/(something)
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(c/.+)?$ http://www.example.com%{REQUEST_URI} [L,R=301]
For 3: redirect direct requests for /index.php
to just /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php
RewriteRule ^ / [L,R=301]
For 4: forbid direct access to anything in the /xy/
directory.
RewriteCond %{HTTP_REFERER} !http://(www\.)?example\.com/ [NC]
RewriteRule ^xy/ - [L,F]
Upvotes: 2