June 3, 201511 yr I created a Rule in my HTACCESS file, to hide a sub-folder. RewriteEngine On RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/?([^/]+)/([^/]+)/([^.]+)\.php [NC] RewriteRule ^ /%1/%3 [R=301,L] RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^([^/]+)/([^/]+)/?$ $1/Project/$2.php [NC,L] The first rule removes all file-extensions : php The second rule will hide the folder "Project" from the URL Both these rules are working perfectly. However, when I tried to add a third rule, to hide another folder, it failed. This second folder (Rolan) is in the same location as the "Project" folder, so I assumed that it should work simply by copy-pasting the second rule, and then adding a PREFIX to the beginning of the third rule : RewriteEngine On RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/?([^/]+)/([^/]+)/([^.]+)\.php [NC] RewriteRule ^ /%1/%3 [R=301,L] RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^([^/]+)/([^/]+)/?$ $1/Project/$2.php RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^gagoo/([^/]+)/([^/]+)/?$ $1/Rolan/$2.php [NC,L] I added the prefix "gagoo" to the third rule. Also, I removed the [NC,L] from the end of the second rule, and placed it at the end of the third rule. Then, in my PHP code, I wrote the URL as follows : www.example.com/gagoo/Rolan/file_name Both the first and second rules are still working. But, for the third rule, I am getting a "FILE NOT FOUND : 404" error The thing is : I wrote a JavaScript code, which opens "file_name" in a "New Window". (Still, I doubt that this could be the reason for the problem)
June 4, 201511 yr Author Try this: RewriteEngine On RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/?([^/]+)/([^/]+)/([^.]+)\.php [NC] RewriteRule ^ /%1/%3 [R=301,L] RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^([^/]+)/([^/]+)/?$ $1/Project/$2.php RewriteRule ^gagoo/([^/]+)/([^/]+)/?$ $1/Rolan/$2.php [NC,L] Thanks, Nock. But, I'm still getting the error "404 : File not found" Am I using the correct URL in my code : /gagoo/Rolan/file_name ? (I also tried removing the "Rolan" from the URL : /gagoo/file_name. But it still does not work) I assume the "Rolan" should NOT be there (since, the purpose of the Rule is to hide the "Rolan" from the URL in the browser, the same way the first Rule hides the "PHP" folder from view)
June 4, 201511 yr Author If you think about your rewrite rule like this: RewriteRule ^gagoo/$1/$2/?$ $1/Rolan/$2.php [NC,L] Then entering '/gagoo/Rolan/file_name' Should take you to: /gagoo/Rolan/Rolan/file_name This is because $1 becomes Rolan and $2 becomes file_name. I'm guessing that the rule that you're really looking for would be something like this: RewriteRule ^gagoo/([^/]+)/([^/]+)/?$ $1/$2.php [NC,L] I am still getting the 404 error Should I write the URL with our without "Rolan" ? /gagoo/file_name or /gagoo/Rolan/file_name ? I tried both; neither are working;
June 4, 201511 yr Author If your rewrite rule has been changed to the one I said above then enter it with 'Rolan'. This will only work if you have a 'file_name.php' file inside a folder called 'Rolan' which is inside a folder called 'gagoo' at the root of your website. If you're using a Linux based server then they will be case sensitive too. Perhaps, it's my fault for not having stated my entire file-structure from the start I simply didn't think it was necessary, because, as I mentioned earlier : the second rule works perfectly. So, I assumed that the same format would work with the third rule. My file structure is as follows (from ROOT folder to file_name) : www.example.com/Principal/Rolan/file_name For the second rule, the file-structure is exactly the same. www.example.com/Principal/Project/file_name When I created the second rule (to hide the Project folder), I changed all my URLs in my php-code, to the following : /Principal/file_name And, it works. the "Project" folder is hidden from view So, naturally, when I wanted to do the same for "Rolan", I thought the same principle applies. But, I guess I was wrong. So............using the new HTACCESS code you just gave me : RewriteRule ^gagoo/([^/]+)/([^/]+)/?$ $1/$2.php [NC,L] I guess that : I should replace "gagoo" with "Rolan"..............and then change all my URL (in the php files) to : /Principal/file_name Am I on the right track ? Edited June 4, 201511 yr by newuserphp
December 14, 201510 yr If the problem is still active, you need to seek help recommend this team Edited December 14, 201510 yr by vdvcv
Create an account or sign in to comment