HTACCESS Rewrite rule

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

HTACCESS Rewrite rule

Post by Kwai chang caine »

Hello at all

I search "simply" to rewrite :

"https://SubDomain1.Domain.fr" in "https://Domain.fr/1/"
"https://SubDomain2.Domain.fr" in "https://Domain.fr/2/"
etc ..


I don't know what is the more simple solution
I have an HTACCESS for rewrite rule and i use CLOUDFLARE since yesterday who apparently can also rewriting rule but i have not understand something, too much hard for my little head :oops:

Before i used a simple redirection in IONOS "SubDomain1.Domain.fr" => "Domain.fr/1/" but i have not found the same function in CLOUDFLARE :oops:

Thanks in advance for your precious help 8)
ImageThe happiness is a road...
Not a destination
User avatar
Caronte3D
Addict
Addict
Posts: 1361
Joined: Fri Jan 22, 2016 5:33 pm
Location: Some Universe

Re: HTACCESS Rewrite rule

Post by Caronte3D »

Try asking to an IA to get something (not tested) like:

Code: Select all

RewriteEngine On

# Redirection for numeric subdomains
RewriteCond %{HTTP_HOST} ^SubDomain([0-9]+)\.Domain\.fr$ [NC]
RewriteRule ^(.*)$ https://Domain.fr/%1/$1 [R=301,L]

replace the subdomain with your own
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: HTACCESS Rewrite rule

Post by Kwai chang caine »

Thanks CARONTE i try that
Have a good day 8)
ImageThe happiness is a road...
Not a destination
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: HTACCESS Rewrite rule

Post by Kwai chang caine »

Apparently that not works :|
ImageThe happiness is a road...
Not a destination
Denis
Enthusiast
Enthusiast
Posts: 778
Joined: Fri Apr 25, 2003 5:10 pm
Location: Doubs - France

Re: HTACCESS Rewrite rule

Post by Denis »

Salut mon bon KCK :D

I'm no good at this

The happiness is a road...
Not a destination

but there's a long way to go
A+
Denis
normeus
Enthusiast
Enthusiast
Posts: 472
Joined: Fri Apr 20, 2012 8:09 pm
Contact:

Re: HTACCESS Rewrite rule

Post by normeus »

KCC,
get rid of the [R=301,L] redirect :

Code: Select all

RewriteRule ^(.*)$ https://Domain.fr/%1/$1
If you have other rules after this, it might change the output

@Carotte3D, AI is the future of young programmers


Norm.
google Translate;Makes my jokes fall flat- Fait mes blagues tombent à plat- Machte meine Witze verpuffen- Eh cumpari ci vo sunari
User avatar
NicTheQuick
Addict
Addict
Posts: 1518
Joined: Sun Jun 22, 2003 7:43 pm
Location: Germany, Saarbrücken
Contact:

Re: HTACCESS Rewrite rule

Post by NicTheQuick »

First of all you need to know what you webserver is. The rewrite rules mentioned above are meant for Apache2. But maybe Cloudflare uses nginx. That should look a bit different. Also on webserver side certain rules can be disabled for the `.htaccess` file. So even if the rule is correct it will never be applied.

I don't know how Cloudflare is working but they seem to provide a lot of documentation: https://developers.cloudflare.com/rules/url-forwarding/
According to ChatGPT you have to go to your Cloudflare Dashboard, select your domain, click on rules, create rule and then for `SubDomain1.Domain.fr` → `Domain.fr/1/` create the rule

IF: Hostname → equals → subdomain1.domain.fr
THEN: Static Redirect → URL: https://domain.fr/1/ (Status: 301 oder 302)
The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: HTACCESS Rewrite rule

Post by Kwai chang caine »

Denis wrote:but there's a long way to go
For sure....because i not found it, even after 60 years :|
On the other hand...when even happy to read you :wink:

@NORMEUS
In fact i have one rule by subdomain :oops:
Really....the man who create this language...had to think for hours, even to put on his pants :mrgreen:

@NICKTHEQUICK
Thanks for your long and interesting explanation 8)
Apparently you have right because when i have an error that write "nginx" in the page :wink:
I have try your tip and that not works too :|
Perhaps it's because i have always the subdomains declared in IONOS ?
I have even delete the HTACCESS and nothing better :|
It's hard for me to understand where i must create the subdomain now i am with CLOUDFLARE ? :oops:
ImageThe happiness is a road...
Not a destination
Post Reply