Htaccess hidding parts of several different paths in URL [Resolved]

For everything that's not in any way related to PureBasic. General chat etc...
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5342
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Htaccess hidding parts of several different paths in URL [Resolved]

Post by Kwai chang caine »

Hello at all

All this day, i search to hide several words in the URL in HtAccess without success :|
I search to have the last folder in several URLS on the same server

Code: Select all

If i have this URL
http://kcc.com/FoderA/FolderA1/FolderA2/FolderA3/FolderA4/index.php
i want have this adress
http://kcc.com/FolderA4/index.php

Code: Select all

or for this adress
http://kcc.com/FolderB1/FolderB2/FolderB3/index.php
i want have this adress
http://kcc.com/FolderB3/index.php
I have see i can hide for exampler one "FolderA" with success

Code: Select all

RewriteCond %{REQUEST_URI} !^/FolderA/
RewriteRule ^(.*)$ /FolderA/$1 [L,QSA] 
But how i can do for explain to Htaccess i want hide several different paths
When i write several rule one after other, only the last works, or worst .....nothing works :|

Code: Select all

RewriteCond %{REQUEST_URI} !^/FoderA/FolderA1/FolderA2/FolderA3/
RewriteRule ^(.*)$ /FolderA/FolderA1/FolderA2/FolderA3/$1 [L,QSA] 

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

I have also see the [OR] exist for adding "RewriteCond" but not understand how use it :|

If someone know about this complex coding...and can help me :oops:
Thanks in advance 8)

Have a good day
Last edited by Kwai chang caine on Sat May 28, 2022 8:17 pm, edited 1 time in total.
ImageThe happiness is a road...
Not a destination
normeus
Enthusiast
Enthusiast
Posts: 414
Joined: Fri Apr 20, 2012 8:09 pm
Contact:

Re: Htaccess hidding parts of several different paths in URL

Post by normeus »

KCC,
I think, if you want to manage folders it might be better to do it with a main index.php that handles all the requests, but that is not your question. Anyway, I hope this is what you are asking:
You want the server to run index.php inside of FolderA4 , but not display the path to the folder:

Code: Select all

http://kcc/FolderA/FolderA1/FolderA2/FolderA3/FolderA4/index.php 
to go to this folder you want people to type:

Code: Select all

http://kcc/FolderA4
and as an example, you also have another folder, and since you are rewriting the request it does not have to be index.php. It can be any php file:

Code: Select all

http://kcc/FolderB/FolderB1/FolderB2/FolderB3/userb4.php
will be turned into:

Code: Select all

http://kcc/FolderB3

Code: Select all

RewriteEngine on
RewriteCond %{REQUEST_URI} ^/FolderA4
RewriteRule ^(.*)$ /FolderA/FolderA1/FolderA2/FolderA3/$1/index.php [L,QSA]
RewriteCond %{REQUEST_URI} ^/FolderB3
RewriteRule ^(.*)$ /FolderB/FolderB1/FolderB2/$1/userb4.php [L,QSA]
There is a website to test your htaccess redirections:

https://htaccess.madewithlove.com/


Norm.
google Translate;Makes my jokes fall flat- Fait mes blagues tombent à plat- Machte meine Witze verpuffen- Eh cumpari ci vo sunari
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5342
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Htaccess hidding parts of several different paths in URL

Post by Kwai chang caine »

Waaaaaoooouuuhh !!!!!
That works exactely like i want !!!!


Image

I am really impressed by the geniuses who manage to understand how HTACCES works. :shock:
Because when I saw that it was based on REGEX, I thought to myself that I was dead. :mrgreen:
And that only a friend from the PB forum would take the time to help me quickly :wink:
One thousand of thanks WebMaster NORMEUS 8)

I have another question, if i can abuse another time of your precious time :oops:
For return to the previous URL, before i used this simple TAG

Code: Select all

<h1><a href='..' style='text-decoration:none'>      ***** RETURN *****</a><br><br></h1>
But obviously, that cannot works now with the HtAccess rule :|
I suppose i'm forcing to use now a javascript code ?
Have an idea to do that ? :oops:
ImageThe happiness is a road...
Not a destination
Post Reply