Page 1 of 1
HTACCESS Rewrite rule
Posted: Fri May 30, 2025 6:49 pm
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
Before i used a simple redirection in IONOS
"SubDomain1.Domain.fr" => "Domain.fr/1/" but i have not found the same function in CLOUDFLARE
Thanks in advance for your precious help

Re: HTACCESS Rewrite rule
Posted: Fri May 30, 2025 7:54 pm
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
Re: HTACCESS Rewrite rule
Posted: Fri May 30, 2025 9:03 pm
by Kwai chang caine
Thanks CARONTE i try that
Have a good day

Re: HTACCESS Rewrite rule
Posted: Sat May 31, 2025 8:12 am
by Kwai chang caine
Apparently that not works

Re: HTACCESS Rewrite rule
Posted: Sat May 31, 2025 11:24 am
by Denis
Salut mon bon KCK
I'm no good at this
The happiness is a road...
Not a destination
but there's a long way to go
Re: HTACCESS Rewrite rule
Posted: Sat May 31, 2025 11:56 am
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.
Re: HTACCESS Rewrite rule
Posted: Sat May 31, 2025 12:14 pm
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)
Re: HTACCESS Rewrite rule
Posted: Sat May 31, 2025 5:58 pm
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
@NORMEUS
In fact i have one rule by subdomain
Really....the man who create this language...had to think for hours, even to put on his pants
@NICKTHEQUICK
Thanks for your long and interesting explanation

Apparently you have right because when i have an error that write "nginx" in the page
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 ?
