How to redirect all attempts to access a folder to index, but server?Rewrite rule for subfolderHow to do url re-writing for MVC purpose in PHPRedirect 301 .htaccess not workingConcrete5.7.5.2 SSL/HTTPS - Invalid form token. Please reload this form and submit againFriendly URL for multiple and long queriesMultiple languages + Htaccesshtaccess - Rewrite all files to index.php except sitemap.xmlRedirection from http to https is not workinghtaccess stop auto redirecting to a unknown folderNeed to fix too many redirects caused by .htaccess on localhost subdirectory

Is it a acceptable way to write a loss function in this form?

That's not my X, its Y is too Z

Diatonic chords of a pentatonic vs blues scale?

Do you have to have figures when playing D&D?

Do you really need a KDF when you have a PRF?

Is Lambda Calculus purely syntactic?

How to destroy a galactic level civilization and still leave behind primitive survivors?

What should I be wary of when insurer is taking a lot of time to decide whether car is repairable or a total loss?

Trying to get (more) accurate readings from thermistor (electronics, math, and code inside)

Make Gimbap cutter

Zig-zag function - coded solution

Is there a DSLR/mirorless camera with minimal options like a classic, simple SLR?

What is the logic behind charging tax _in the form of money_ for owning property when the property does not produce money?

If I had a daughter who (is/were/was) cute, I would be very happy

Use 1 9 6 2 in this order to make 75

Is it okay to have a sequel start immediately after the end of the first book?

Why is the length of the Kelvin unit of temperature equal to that of the Celsius unit?

Does a (nice) centerless group always have a centerless profinite completion?

How to write a convincing religious myth?

Multiband vertical antenna not working as expected

Housemarks (superimposed & combined letters, heraldry)

Confused with atmospheric pressure equals plastic balloon’s inner pressure

Difference between prepositions in "...killed during/in the war"

How and why do references in academic papers work?



How to redirect all attempts to access a folder to index, but server?


Rewrite rule for subfolderHow to do url re-writing for MVC purpose in PHPRedirect 301 .htaccess not workingConcrete5.7.5.2 SSL/HTTPS - Invalid form token. Please reload this form and submit againFriendly URL for multiple and long queriesMultiple languages + Htaccesshtaccess - Rewrite all files to index.php except sitemap.xmlRedirection from http to https is not workinghtaccess stop auto redirecting to a unknown folderNeed to fix too many redirects caused by .htaccess on localhost subdirectory






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I'm creating a new web site.



The structure of this website is:



root
├─ .htaccess
├─ Index.php
└─ Data
└─Logo.png


My index page contains:



<html>
<head>
<meta charset="UTF-8">
</head>
<body>
<img src="Data/Logo.png" alt="logo" height="42" width="42">
</body>
</html>


And my .htaccess:



ErrorDocument 404 https://www.example.com/

RewriteEngine On
RewriteCond %SERVER_PORT !=443
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]

Options +SymLinksIfOwnerMatch
RewriteEngine On
RewriteCond %REQUEST_FILENAME !-f
RewriteCond %REQUEST_FILENAME !-d
RewriteRule . /index.php [L]

RewriteEngine On
RedirectMatch 404 ^/Data/.*$


My problem:



If in .htaccess file i set RedirectMatch 404 ^/Data/.*$ , then no visitor is able to access example.com/Data/Logo.png , but index.php can't show the image.



If in .htaccess file i set RedirectMatch 404 ^/Data/?$ , then Index.php is able to show the image, but any visitor can access to example.com/Data/Logo.png



I want /Data to store images, php functions, styles and every other class.



My question:



How must i configure htaccess file to deny access to all visitors, but allow Index.php (and any other page in the website) to acces that folder?










share|improve this question
























  • Why would you want to do that? Look at it from this perspective: you published the contents of the Data folder, makes sense, since you want for example use the images in there in your application. So you grant access to those files. Now suddenly you say "yeah, I published that, but actually I do not really want clients to be able to access that stuff". That does not make sense. Why should it be relevant how the client accesses that image? What is so unbelievable important in taht image that you need to keep it back, although you want to publish it?

    – arkascha
    Mar 25 at 10:14











  • The only approach to implement what you want, apart from a decent session management, is to rely on the HTTP_REFERER http header sent by the clients. This however is not reliable (robust) at all, since it is trivial to get around that limitation then, http headers can be change how ever the client wants to without you on the server side being able to realize that. So the effort for such a "protection" is more than questionable.

    – arkascha
    Mar 25 at 10:26











  • The reason to conceal the folder is because in it is where all styles, php classes, mysql connection classes and other stuff is going to be stored. Remaking the question a little. If i make a php-mysql connection class to be referenced by another html class, is this new class "Hackable" or "Viewable"? I mean, is there a way any client could see the code in it, or is just viewable to the server?

    – Lluxed
    Mar 26 at 0:26











  • A questionable way of reasoning. Sure, your code is accessible for clients. But as already said: that is imanent to web applications, you want clients to be able to access things. If you are afraid of that then this is a symptom of a lack in confidence. Then that is what you should tackle... In general, as long as your http server is setup to interpret code and you have not implemented effort do specifically make code available there is no way a client can somehow "rip" the php code from the http server. CSS rules and JS code can be retrieved, sure, but as written: that is what want!

    – arkascha
    Mar 26 at 7:55

















0















I'm creating a new web site.



The structure of this website is:



root
├─ .htaccess
├─ Index.php
└─ Data
└─Logo.png


My index page contains:



<html>
<head>
<meta charset="UTF-8">
</head>
<body>
<img src="Data/Logo.png" alt="logo" height="42" width="42">
</body>
</html>


And my .htaccess:



ErrorDocument 404 https://www.example.com/

RewriteEngine On
RewriteCond %SERVER_PORT !=443
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]

Options +SymLinksIfOwnerMatch
RewriteEngine On
RewriteCond %REQUEST_FILENAME !-f
RewriteCond %REQUEST_FILENAME !-d
RewriteRule . /index.php [L]

RewriteEngine On
RedirectMatch 404 ^/Data/.*$


My problem:



If in .htaccess file i set RedirectMatch 404 ^/Data/.*$ , then no visitor is able to access example.com/Data/Logo.png , but index.php can't show the image.



If in .htaccess file i set RedirectMatch 404 ^/Data/?$ , then Index.php is able to show the image, but any visitor can access to example.com/Data/Logo.png



I want /Data to store images, php functions, styles and every other class.



My question:



How must i configure htaccess file to deny access to all visitors, but allow Index.php (and any other page in the website) to acces that folder?










share|improve this question
























  • Why would you want to do that? Look at it from this perspective: you published the contents of the Data folder, makes sense, since you want for example use the images in there in your application. So you grant access to those files. Now suddenly you say "yeah, I published that, but actually I do not really want clients to be able to access that stuff". That does not make sense. Why should it be relevant how the client accesses that image? What is so unbelievable important in taht image that you need to keep it back, although you want to publish it?

    – arkascha
    Mar 25 at 10:14











  • The only approach to implement what you want, apart from a decent session management, is to rely on the HTTP_REFERER http header sent by the clients. This however is not reliable (robust) at all, since it is trivial to get around that limitation then, http headers can be change how ever the client wants to without you on the server side being able to realize that. So the effort for such a "protection" is more than questionable.

    – arkascha
    Mar 25 at 10:26











  • The reason to conceal the folder is because in it is where all styles, php classes, mysql connection classes and other stuff is going to be stored. Remaking the question a little. If i make a php-mysql connection class to be referenced by another html class, is this new class "Hackable" or "Viewable"? I mean, is there a way any client could see the code in it, or is just viewable to the server?

    – Lluxed
    Mar 26 at 0:26











  • A questionable way of reasoning. Sure, your code is accessible for clients. But as already said: that is imanent to web applications, you want clients to be able to access things. If you are afraid of that then this is a symptom of a lack in confidence. Then that is what you should tackle... In general, as long as your http server is setup to interpret code and you have not implemented effort do specifically make code available there is no way a client can somehow "rip" the php code from the http server. CSS rules and JS code can be retrieved, sure, but as written: that is what want!

    – arkascha
    Mar 26 at 7:55













0












0








0


0






I'm creating a new web site.



The structure of this website is:



root
├─ .htaccess
├─ Index.php
└─ Data
└─Logo.png


My index page contains:



<html>
<head>
<meta charset="UTF-8">
</head>
<body>
<img src="Data/Logo.png" alt="logo" height="42" width="42">
</body>
</html>


And my .htaccess:



ErrorDocument 404 https://www.example.com/

RewriteEngine On
RewriteCond %SERVER_PORT !=443
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]

Options +SymLinksIfOwnerMatch
RewriteEngine On
RewriteCond %REQUEST_FILENAME !-f
RewriteCond %REQUEST_FILENAME !-d
RewriteRule . /index.php [L]

RewriteEngine On
RedirectMatch 404 ^/Data/.*$


My problem:



If in .htaccess file i set RedirectMatch 404 ^/Data/.*$ , then no visitor is able to access example.com/Data/Logo.png , but index.php can't show the image.



If in .htaccess file i set RedirectMatch 404 ^/Data/?$ , then Index.php is able to show the image, but any visitor can access to example.com/Data/Logo.png



I want /Data to store images, php functions, styles and every other class.



My question:



How must i configure htaccess file to deny access to all visitors, but allow Index.php (and any other page in the website) to acces that folder?










share|improve this question
















I'm creating a new web site.



The structure of this website is:



root
├─ .htaccess
├─ Index.php
└─ Data
└─Logo.png


My index page contains:



<html>
<head>
<meta charset="UTF-8">
</head>
<body>
<img src="Data/Logo.png" alt="logo" height="42" width="42">
</body>
</html>


And my .htaccess:



ErrorDocument 404 https://www.example.com/

RewriteEngine On
RewriteCond %SERVER_PORT !=443
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]

Options +SymLinksIfOwnerMatch
RewriteEngine On
RewriteCond %REQUEST_FILENAME !-f
RewriteCond %REQUEST_FILENAME !-d
RewriteRule . /index.php [L]

RewriteEngine On
RedirectMatch 404 ^/Data/.*$


My problem:



If in .htaccess file i set RedirectMatch 404 ^/Data/.*$ , then no visitor is able to access example.com/Data/Logo.png , but index.php can't show the image.



If in .htaccess file i set RedirectMatch 404 ^/Data/?$ , then Index.php is able to show the image, but any visitor can access to example.com/Data/Logo.png



I want /Data to store images, php functions, styles and every other class.



My question:



How must i configure htaccess file to deny access to all visitors, but allow Index.php (and any other page in the website) to acces that folder?







php html5 apache .htaccess






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 24 at 22:02







Lluxed

















asked Mar 24 at 21:54









LluxedLluxed

86




86












  • Why would you want to do that? Look at it from this perspective: you published the contents of the Data folder, makes sense, since you want for example use the images in there in your application. So you grant access to those files. Now suddenly you say "yeah, I published that, but actually I do not really want clients to be able to access that stuff". That does not make sense. Why should it be relevant how the client accesses that image? What is so unbelievable important in taht image that you need to keep it back, although you want to publish it?

    – arkascha
    Mar 25 at 10:14











  • The only approach to implement what you want, apart from a decent session management, is to rely on the HTTP_REFERER http header sent by the clients. This however is not reliable (robust) at all, since it is trivial to get around that limitation then, http headers can be change how ever the client wants to without you on the server side being able to realize that. So the effort for such a "protection" is more than questionable.

    – arkascha
    Mar 25 at 10:26











  • The reason to conceal the folder is because in it is where all styles, php classes, mysql connection classes and other stuff is going to be stored. Remaking the question a little. If i make a php-mysql connection class to be referenced by another html class, is this new class "Hackable" or "Viewable"? I mean, is there a way any client could see the code in it, or is just viewable to the server?

    – Lluxed
    Mar 26 at 0:26











  • A questionable way of reasoning. Sure, your code is accessible for clients. But as already said: that is imanent to web applications, you want clients to be able to access things. If you are afraid of that then this is a symptom of a lack in confidence. Then that is what you should tackle... In general, as long as your http server is setup to interpret code and you have not implemented effort do specifically make code available there is no way a client can somehow "rip" the php code from the http server. CSS rules and JS code can be retrieved, sure, but as written: that is what want!

    – arkascha
    Mar 26 at 7:55

















  • Why would you want to do that? Look at it from this perspective: you published the contents of the Data folder, makes sense, since you want for example use the images in there in your application. So you grant access to those files. Now suddenly you say "yeah, I published that, but actually I do not really want clients to be able to access that stuff". That does not make sense. Why should it be relevant how the client accesses that image? What is so unbelievable important in taht image that you need to keep it back, although you want to publish it?

    – arkascha
    Mar 25 at 10:14











  • The only approach to implement what you want, apart from a decent session management, is to rely on the HTTP_REFERER http header sent by the clients. This however is not reliable (robust) at all, since it is trivial to get around that limitation then, http headers can be change how ever the client wants to without you on the server side being able to realize that. So the effort for such a "protection" is more than questionable.

    – arkascha
    Mar 25 at 10:26











  • The reason to conceal the folder is because in it is where all styles, php classes, mysql connection classes and other stuff is going to be stored. Remaking the question a little. If i make a php-mysql connection class to be referenced by another html class, is this new class "Hackable" or "Viewable"? I mean, is there a way any client could see the code in it, or is just viewable to the server?

    – Lluxed
    Mar 26 at 0:26











  • A questionable way of reasoning. Sure, your code is accessible for clients. But as already said: that is imanent to web applications, you want clients to be able to access things. If you are afraid of that then this is a symptom of a lack in confidence. Then that is what you should tackle... In general, as long as your http server is setup to interpret code and you have not implemented effort do specifically make code available there is no way a client can somehow "rip" the php code from the http server. CSS rules and JS code can be retrieved, sure, but as written: that is what want!

    – arkascha
    Mar 26 at 7:55
















Why would you want to do that? Look at it from this perspective: you published the contents of the Data folder, makes sense, since you want for example use the images in there in your application. So you grant access to those files. Now suddenly you say "yeah, I published that, but actually I do not really want clients to be able to access that stuff". That does not make sense. Why should it be relevant how the client accesses that image? What is so unbelievable important in taht image that you need to keep it back, although you want to publish it?

– arkascha
Mar 25 at 10:14





Why would you want to do that? Look at it from this perspective: you published the contents of the Data folder, makes sense, since you want for example use the images in there in your application. So you grant access to those files. Now suddenly you say "yeah, I published that, but actually I do not really want clients to be able to access that stuff". That does not make sense. Why should it be relevant how the client accesses that image? What is so unbelievable important in taht image that you need to keep it back, although you want to publish it?

– arkascha
Mar 25 at 10:14













The only approach to implement what you want, apart from a decent session management, is to rely on the HTTP_REFERER http header sent by the clients. This however is not reliable (robust) at all, since it is trivial to get around that limitation then, http headers can be change how ever the client wants to without you on the server side being able to realize that. So the effort for such a "protection" is more than questionable.

– arkascha
Mar 25 at 10:26





The only approach to implement what you want, apart from a decent session management, is to rely on the HTTP_REFERER http header sent by the clients. This however is not reliable (robust) at all, since it is trivial to get around that limitation then, http headers can be change how ever the client wants to without you on the server side being able to realize that. So the effort for such a "protection" is more than questionable.

– arkascha
Mar 25 at 10:26













The reason to conceal the folder is because in it is where all styles, php classes, mysql connection classes and other stuff is going to be stored. Remaking the question a little. If i make a php-mysql connection class to be referenced by another html class, is this new class "Hackable" or "Viewable"? I mean, is there a way any client could see the code in it, or is just viewable to the server?

– Lluxed
Mar 26 at 0:26





The reason to conceal the folder is because in it is where all styles, php classes, mysql connection classes and other stuff is going to be stored. Remaking the question a little. If i make a php-mysql connection class to be referenced by another html class, is this new class "Hackable" or "Viewable"? I mean, is there a way any client could see the code in it, or is just viewable to the server?

– Lluxed
Mar 26 at 0:26













A questionable way of reasoning. Sure, your code is accessible for clients. But as already said: that is imanent to web applications, you want clients to be able to access things. If you are afraid of that then this is a symptom of a lack in confidence. Then that is what you should tackle... In general, as long as your http server is setup to interpret code and you have not implemented effort do specifically make code available there is no way a client can somehow "rip" the php code from the http server. CSS rules and JS code can be retrieved, sure, but as written: that is what want!

– arkascha
Mar 26 at 7:55





A questionable way of reasoning. Sure, your code is accessible for clients. But as already said: that is imanent to web applications, you want clients to be able to access things. If you are afraid of that then this is a symptom of a lack in confidence. Then that is what you should tackle... In general, as long as your http server is setup to interpret code and you have not implemented effort do specifically make code available there is no way a client can somehow "rip" the php code from the http server. CSS rules and JS code can be retrieved, sure, but as written: that is what want!

– arkascha
Mar 26 at 7:55












0






active

oldest

votes












Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55328942%2fhow-to-redirect-all-attempts-to-access-a-folder-to-index-but-server%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55328942%2fhow-to-redirect-all-attempts-to-access-a-folder-to-index-but-server%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript