Reputation: 709
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
Upvotes: 1
Views: 42
Reputation: 24458
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
Upvotes: 1