1

before this thread is marked as a "duplicate", or down-voted by someone eager.......kindly allow me to address my issue first :)

Despite having dozens of various solutions to this issue online, none seem to work for me.

I'm trying to hide a folder, so it does not display in my URL.

My domain name is : www.example.com

My login file is within the "PHP" folder.

So, the login URL is : www.example.com/PHP/login.php

I am trying to hide the "PHP", so the URL displays as :

www.example.com/login.php

I've copy-pasted several examples from this forum, but nothing seems to work.

I've tried this :

  RewriteEngine On
  RewriteCond %{REQUEST_URI} !^/PHP/
  RewriteRule ^(.*)$ /PHP/$1 

or this.........

 RewriteEngine On
 RewriteCond %{REQUEST_URI} !^/PHP
 RewriteRule ^(.*)$ PHP/ $1 

(i.e., I removed the trailing slashes)

Nothing works. The URL continues to load normally.

The only time I get an error is when I include the "[L]" at the end of the code :

RewriteEngine On
RewriteCond %{REQUEST_URI} !^/PHP/
RewriteRule ^(.*)$ /PHP/ $1 [L]

Then, I get a "403" error..........which makes sense, seeing as the "[L]" prevents any further Re-write commands from executing. And I have a few of them in my HTACCESS file.

Here is my complete HTACCESS file :

 RewriteEngine on
 RewriteBase /

 RewriteCond %{HTTP_HOST} ^(www.)?example.com$
 RewriteRule ^/PHP/(.*)$ http://www.example.com/$1 [L,R=301]

 #RewriteCond %{REQUEST_URI} !^PHP/
 #RewriteRule ^(.*)$ PHP/$1 [L]

 RewriteCond %{REQUEST_FILENAME} !-d 
 RewriteCond %{REQUEST_FILENAME}\.php -f 
 RewriteRule ^(.*)$ $1.php

 RewriteRule ^index\.php$ - [L]
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteRule . /index.php [L]

(Note the two lines which are commented-out. )

phpnewbie2015
  • 346
  • 1
  • 3
  • 15
  • maybe you have not enabled the rewrite module for apache. Check this out: http://stackoverflow.com/questions/869092/how-to-enable-mod-rewrite-for-apache-2-2 try `a2enmod rewrite` and restart apache – steven May 19 '15 at 14:36
  • possible duplicate of [Remove subfolder from WordPress URL using htaccess](http://stackoverflow.com/questions/22301752/remove-subfolder-from-wordpress-url-using-htaccess) – Kristiyan May 19 '15 at 14:37
  • Re-write module is enabled. I have other codes in my HTACCESS file, and they all work perfectly. – phpnewbie2015 May 19 '15 at 14:37
  • Shouldn't it be `RewriteCond %{REQUEST_URI} ^/PHP$` or `RewriteCond %{REQUEST_URI} ^/PHP/(.*)$`??? – steven May 19 '15 at 14:39
  • I already tried both ways. I have updated my post, to show my full HTACCESS file – phpnewbie2015 May 19 '15 at 14:47

1 Answers1

1

Give this a try and see if it works for you.

  RewriteEngine On
  RewriteBase /
  RewriteCond %{THE_REQUEST} [A-Z]{3,}\ /PHP/([^&\ ]+)
  RewriteRule ^ /%1? [R=301,L]

Adding it with your current rules.

 RewriteEngine on
 RewriteBase /

 RewriteCond %{HTTP_HOST} ^(www.)?example.com$
 RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]

 RewriteCond %{THE_REQUEST} [A-Z]{3,}\ /PHP/([^&\ ]*)
 RewriteRule ^ /%1? [R=301,L]

 RewriteCond %{REQUEST_FILENAME} !-d 
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_URI} !^/PHP [NC] 
 RewriteRule ^(.+)$ /PHP/$1.php [L]

 RewriteRule ^/?$ /PHP/$1 [L]
Panama Jack
  • 23,020
  • 10
  • 59
  • 90
  • Thanks, Panama Jack. It worked. the PHP folder was removed from the URL....................but.............I got a 404-error : FILE NOT FOUND. – phpnewbie2015 May 19 '15 at 14:56
  • Where did you place the rules? – Panama Jack May 19 '15 at 14:59
  • I simply copy-pasted your example. Exactly as you wrote it (the entire HTACCESS file). – phpnewbie2015 May 19 '15 at 15:06
  • Is it possible that the the problem lies with one of these : [R=301,L]................or............[L,R=301] ? – phpnewbie2015 May 19 '15 at 15:08
  • Do you just want to redirect login.php or is there anything else you need to redirect in php folder? – Panama Jack May 19 '15 at 15:10
  • I simply want to hide the PHP folder from view. the login.php is inside the PHP folder. As I stated : I want my URL to say : www.example.com/login.php (well, actually, as you can see from my HTACCESS file, I already removed all php file extensions; but, that is irrelevant to the current issue) – phpnewbie2015 May 19 '15 at 15:14
  • Ok so you just wanted to remove php folder if some one enters http://example.com/php/login.php? I see you hide php extention but not for the php folder. – Panama Jack May 19 '15 at 15:22
  • Yes. As I stated in my post : I simply want to remove the PHP folder from view : www.example.com/login.php....................... – phpnewbie2015 May 19 '15 at 15:25
  • I edited my anewer. I just left the part that removed the php folder if php folder is in the url. – Panama Jack May 19 '15 at 15:28
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/78222/discussion-between-phpnewbie2015-and-panama-jack). – phpnewbie2015 May 19 '15 at 15:37
  • Hi Panama still getting the 404 error Here is what I am going to do : I will put the PHP folder inside another folder, and see if that helps : www.example.com/FOLDER/PHP/login.php Nope. Still not helping :( – phpnewbie2015 May 19 '15 at 15:45
  • Its getting a 404 because you don't have a rule to handle rewriting it to the php folder. Your other rules are picking it up. You have a lot of stuff going on. Are you also running wordpress? – Panama Jack May 19 '15 at 15:49
  • No I am not running wordpress – phpnewbie2015 May 19 '15 at 16:04