Htaccess issue

I’m trying to write some htaccess code that will prevent users from being able to go to a sub-directly directly or any directories within that sub-directory.

For example:

http://www.website.com/sub-directory/ - redirect to an error page
http://www.website.com/sub-directory/* (or anything else down this path) - redirect to an error page

Thank you in advance

Well, you will need something like this:

RewriteRule ^some_directory/(.*)$ error_page.php [L,nc]

Let me know if this works.

You would have to add RewriteEngine on to make that work.

I would use this instead however;


RedirectMatch permanent ^/some_directory/(.*)$ /error_page.php

[QUOTE=sekasi;2337210]You would have to add RewriteEngine on to make that work.

I would use this instead however;


RedirectMatch permanent ^/some_directory/(.*)$ /error_page.php

[/QUOTE]

Interesting… I’m not so familiar with other htaccess rules like this. Would you recommend any particular website with clear and concise examples?

What’s so special or different about “RedirectMatch”?

RewriteRule and RedirectMatch belong to two seperate modules in your apache installation. There’s obviously a lot of things that differ, but the most important ones would be;

RedirectMatch is going to physically move you to the url you specify, with less control over the users address bar. The rewriteengine doesn’t need to be activated, hence less memory usage.

If you want the address bar to show something else than what you’re directing them to however, making a RewriteRule is better.

[QUOTE=sekasi;2337433]RewriteRule and RedirectMatch belong to two seperate modules in your apache installation. There’s obviously a lot of things that differ, but the most important ones would be;

RedirectMatch is going to physically move you to the url you specify, with less control over the users address bar. The rewriteengine doesn’t need to be activated, hence less memory usage.

If you want the address bar to show something else than what you’re directing them to however, making a RewriteRule is better.[/QUOTE]

Ah, alright. So, let’s say I needed to not only make sure that a user can’t access a directory, but then also rewrite the url, like so:

RedirectMatch permanent ^/some_directory/(.*)$ /error.php?error=2

then

rewrite “/error.php?error=2” to just “/error”

Alright,

I’ve got some issues. Although I do not want anyone to be able to access:

www.website.com/admin-cp/*

I do, however, want users to be able to access:

www.website.com/virtualfolder/admin-cp/*

It can’t seem to figure out how to deny one, but allow the other… it keeps applying the rule no matter what.

try


RewriteCond %{REQUEST_URI} !^/([a-zA-Z0-9-._/]*)/?
#rest of ur code here

[QUOTE=simplistik;2337508]try


RewriteCond %{REQUEST_URI} !^/([a-zA-Z0-9-._/]*)/?
#rest of ur code here

[/QUOTE]

What exactly would the rest of the code be for my circumstance?

[QUOTE=dColumbus;2337623]What exactly would the rest of the code be for my circumstance?[/QUOTE]

Whatever you figured out in the first 20 posts

[QUOTE=simplistik;2337754]Whatever you figured out in the first 20 posts[/QUOTE]

Ok, not to be an **… but, I wouldn’t still be asking you questions if it was figured out. There are two ways of doing this, from what I understand… however, if you could explain what the heck "RewriteCond %{REQUEST_URI} !^/([a-zA-Z0-9-._/])/?" even does… to me, all that looks like it’s doing it checking with a condition for ANY sub-domain name. I need mine to be specific.

This does not work:

RewriteCond %{REQUEST_URI} !^/([a-zA-Z0-9-._/])/?
RewriteRule ^some_directory/(.
)$ error_page.php [L,nc]

Which, I believe is what you told me do to…