1

I am trying to remove the url.com/php/ (/php/) part of my url and have tried to use htaccess with the following lines

RewriteCond %{REQUEST_URI} !^/php RewriteRule (.*) /php/$1 [QSA,L] 

but received this error on server:

The requested URL /php/index.php was not found on this server.

It is actually adding /php/ after my url.com address in every scenario. I have tried a plethora of other threads all with different results but this one actually removes /php/ from the url, just in this case is assuming that /php/ belongs there every time. Any ideas on how to fix this?

Thanks

Edit: Now that I think about it, I'm actually trying to rewrite the entire folder tree so that only the filename and url show up.

So url.com/php/ra/file.php?id=1 shows up as url.com/file.php?id=1

My entire htaccess file to eliminate confusion:

# Use PHP5.4 Single php.ini as default AddHandler application/x-httpd-php54s .php Options -Indexes +FollowSymLinks -MultiViews RewriteEngine On RewriteCond %{SERVER_PORT} 80 RewriteRule ^(.*)$ https://urlreplaced.com/$1 [R,L] RewriteCond %{REQUEST_URI} !^/php RewriteRule (.*) /php/$1 [QSA,L] 

edit2: Apologies for the confusion.

my site url is : https://www.url.com

currently /php/ is next level down and within that is /ea/ , /hbu/ , /hc/, /ra/, /st/, and /tut/

php contains a lot of files but all ending in .php and accepting GET vars

as well as each directory with probably 100 .php files in each. If I understand what I've read so far about this issue correctly doesn't $1 after the subdirectory cover what files are inside of it?

I need any and all files past the /php/ directory to show up in the URL as url.com/example.php?var=x no matter what subdirectory is past that.

So whether example.php exists in /php/ra or /php/hbu or just plain /php it still amounts to url.com/example.php

Thanks for your help

1
  • Have you turned the RewriteEngine on in the .htaccess file? Commented Jun 24, 2015 at 2:56

1 Answer 1

1

Based on the URL's you provided in your edit, if you just want to remove the PHP path from the URL and leave the filename and query string you can do this.

 RewriteEngine On #rewrite http to https RewriteCond %{HTTPS} off RewriteRule ^(.*)$ https://urlreplaced.com/$1 [R=301,L] #if full real URL is used, redirect to file.php RewriteCond %{THE_REQUEST} [A-Z]{3,}\ /+php/ra/file\.php\?id=([^&\ ]+) RewriteRule ^ file.php?id=%1 [R=301,L] #if request is a real file or directory do nothing RewriteCond %{REQUEST_FILENAME} -f [OR] RewriteCond %{REQUEST_FILEMAME} -d RewriteRule ^ - [L] #rewrite full path to file.php RewriteCond %{QUERY_STRING} ^id=(.+)$ RewriteRule ^file\.php$ /php/ra/file.php?id=%1 [L] 

So now your URL can be like this.

http://example.com/file.php?id=30 
Sign up to request clarification or add additional context in comments.

5 Comments

so /ra/ was just an example directory, I have a lot of them within the /php/ folder as well as hundreds of files that I obviously can't write individual rules for. I'm not familiar with how htaccess scripts work so which parts of your reply would I need to replicate to reach all the individual subdirectories? I have 5 or so that I need to duplicate the rewrite for. Also how can I wildcard the filename? It's obviously not file.php
Examples like that tend to not help. We have to know the exact requirements or I can't give a proper solution. If you give a specific example/file, I give a specific answer. Update your question with the exact requirements and see if it can be done the way you want it.
apologies I edited my post again. I mostly am just having trouble understanding how the code you wrote functions and was more so looking for a further explanation so I could take a crack at it.
So whether example.php exists in /php/ra or /php/hbu or just plain /php it still amounts to hospitaldatasolutions.com/example.php That will not work. How will apache know which folder to check for that file? you can't have a simple file and expect it to know which folder to look in. That's not how rewrite works.
I'm just trying to hide my directory structure. I can't just tell it that if someone goes to a file in a certain directory to remove /php/ra from the url? Even with multiple .htaccess files for each directory?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.