App.php - Rewrite subdomain

Discussion forum for Extension Writers regarding Extension Development.
Post Reply
User avatar
PGreca
Registered User
Posts: 48
Joined: Mon Oct 29, 2018 12:36 pm
Location: Italy
Contact:

App.php - Rewrite subdomain

Post by PGreca »

I'm developing the extension using the routing of 'app.php' .
I'm searching a solution for assign the routing/rewrite a subdomain
Example:
'pgreca.it/app.php/example/' -> 'example.pgreca.it/'
'pgreca.it/app.php/social/' -> 'social.pgreca.it/'

'pgreca.it/example/' -> 'example.pgreca.it'
'pgreca.it/social/' -> 'social.pgreca.it'

I tryed with .htaccess both DNS, but them didn't work.
Searching the documention on symphony i found it this: https://symfony.com/doc/current/routing.html
And i' more confused from before...
Do you know how i can have the volute rewrite? Is it possible do what i want?

---
Sorry for my english, but it's really complicated for me explain what i want do

User avatar
3Di
Former Team Member
Posts: 14981
Joined: Mon Apr 04, 2005 11:09 pm
Location: Milan (IT) Frankfurt (DE)
Name: Marco
Contact:

Re: App.php - Rewrite subdomain

Post by 3Di »

In ACP / Server settings -> Enable URL Rewriting: YES.
No need to mess with htaccess.

Ah sorry, mis-read.
Anyway, that's not the right forum where to ask coding questions, instead try at the "writers" one.
Please PM me only to request paid works. Thx.
Want to compensate me for my interest? Donate
My development's activity º PhpStorm's proud user
Extensions, Scripts, MOD porting, Update/Upgrades
:studio_microphone: Premium extensions @ The Studio

User avatar
EA117
Registered User
Posts: 1368
Joined: Wed Aug 15, 2018 3:23 am
Contact:

Re: App.php - Rewrite subdomain

Post by EA117 »

Are you wanting to do it in APP.PHP, or do you think you need to do it in APP.PHP?

Asking since you said "extension", but then immediately described trying to use .htaccess.

You should definitely be able to achieve this in .htaccess, without ever hitting APP.PHP. But that's "if you want to."

Directives like this should work in the .htaccess:

Code: Select all

Redirect 301 /example https://example.pgreca.it
Redirect 301 /app.php/example https://example.pgreca.it
You might also want to use "302" while testing instead of "301", so that browsers won't be as likely to cache any testing mistakes; making it harder to tell when you subsequently fix something.

User avatar
PGreca
Registered User
Posts: 48
Joined: Mon Oct 29, 2018 12:36 pm
Location: Italy
Contact:

Re: App.php - Rewrite subdomain

Post by PGreca »

I think i need to do this in APP.PHP.
With:

Code: Select all

Redirect 301 /example https://example.pgreca.it
Redirect 301 /app.php/example https://example.pgreca.it
I have a redirect when visit the 'app.php', but i need to rewrite the url for the app.php.

So i' m searcing a solution for rewrite the "Routing" with .htaccess

For have the url: "example.pgreca.it", where the EXAMPLE is the "app.php/example/"

I have read some documentation of Symphony, but i' not found nothing can help me.

---
Sorry for my english, but it's really complicated for me explain what i want do (x2)

User avatar
EA117
Registered User
Posts: 1368
Joined: Wed Aug 15, 2018 3:23 am
Contact:

Re: App.php - Rewrite subdomain

Post by EA117 »

I'm not sure I understand completely or correctly yet. Perhaps someone else who knows more about the routing behavior can recognize what you're asking or intending to accomplish.

It seems like you're describing something similar to what phpBB's own default .htaccess rule does. e.g. If you make a request like http://domain.com/foo -- but "foo" does not exist as a folder, and "foo" does not exist as a file -- then the rule in the default .htaccess that phpBB provides will re-write that URL to be http://domain.com/app.php/foo to allow checking whether phpBB or installed extensions handle that path as a route.

Based on your earlier description ("'pgreca.it/app.php/example/' -> 'example.pgreca.it/'"), it sounded like if someone enters http://pgreca.it/app.php/example/, you want them to be sent to http://example.pgreca.it/ instead? Is that correct?

Or do I have it backwards, and you want someone who enters http://example.pgreca.it/ to be sent to http://pgreca.it/app.php/example/? I'm thinking now you must mean this way, and this is why the understanding of routes is important.

User avatar
PGreca
Registered User
Posts: 48
Joined: Mon Oct 29, 2018 12:36 pm
Location: Italy
Contact:

Re: App.php - Rewrite subdomain

Post by PGreca »

EA117 wrote:
Wed Oct 30, 2019 5:32 am
Or do I have it backwards, and you want someone who enters http://example.pgreca.it/ to be sent to http://pgreca.it/app.php/example/? I'm thinking now you must mean this way, and this is why the understanding of routes is important.
I need this rewrite

User avatar
EA117
Registered User
Posts: 1368
Joined: Wed Aug 15, 2018 3:23 am
Contact:

Re: App.php - Rewrite subdomain

Post by EA117 »

EA117 wrote:
Wed Oct 30, 2019 5:32 am
...you want someone who enters http://example.pgreca.it/ to be sent to http://pgreca.it/app.php/example/
Okay, understood; thanks for the confirmation. Your question still appears to be specific to "how do I perform the DNS-level or web server-level redirect needed to make example.pgreca.it redirect to pgreca.it/app.php/example", correct? And is not yet a question of "how do I handle in PHP a request to /app.php/example once such a request has been made."

Assuming this is still a correct understanding of the question:

You may need to consult with your web server hosting service to determine which options you actually have available to achieve this within your existing hosting plan and/or within your existing DNS provider. Or possibly what changes / upgrades you might need in order to best achieve it, both for now and for additional subdomains you might want in the future.

The only site we can say your current .htaccess is able to control "right now" is the http://pgreca.it/ site where phpBB is currently running.

The additional subdomains like http://example.pgreca.it may be able to be configured to point to the same document root as the http://pgreca.it/ site, and therefore you would control the redirects through the same .htaccess file. If you can configure them all to point to this same document root, then you will only need to edit the .htaccess file in your phpBB directory to setup the subdomain redirects. i.e. Requests for both http://pgreca.it/ and for http://example.pgreca.it/ would pass through that same single .htaccess file, and you would create the rules needed to rewrite the http://example.pgreca.it/ request or other subdomain requests within that single .htaccess file.

Or, you might be forced to set each subdomain to its own unique document root directory. In that case you would have to create a separate .htaccess file in each of those root directories, each of which will do nothing except redirect requests to the main http://pgreca.it/ site. e.g. There would be a separate document root specifically for handling http://example.pgreca.it/, and the .htaccess in that document root wouldn't do anything except redirect requests to your main site's http://pgreca.it/app.php/example path.

How exactly you would configure your existing web server / hosting plan for either of these scenarios is up to your hosting provider. e.g. It could be a feature they call "Add-on Domains", or maybe they have some other way to achieve it. Whether their system allows you to point all domains to a single document root or "forces" you to have separate document roots is again up to them.

Note it's not a question of "are you able to create a DNS subdomain", which you presumably can. It's more specifically a question of "is the web server configured to expect requests for this new subdomain", which is why your hosting provider and the features your current plan provides are important. Simply creating a subdomain and assigning the DNS record the IP address of your main site's web server isn't enough; the web server will likely reject any requests that are for a subdomain the web server hasn't been configured to handle.

Your DNS provider may possibly also offer it's own kind of "Forwarding" option, where they allow you to setup an HTTP redirect for DNS domains you create. That is not "a feature of DNS", but rather is simply the DNS provider themselves setting up the the web server needed to receive the requests for that new domain, and then also automatically creating an .htaccess configured to redirect to the alternate URL you specified. i.e. The DNS provider is simply doing the same kind of job that your hosting service might also provide for how to handle these subdomains.

Once you have the subdomains successfully handled by a web server -- whether by pointing them all to the same document root and using the single .htaccess to redirect them appropriately, or by having separate document roots or a DNS "Forwarding" setup with an individual .htaccess redirect per subdomain -- then you would be at the point to proceed with handing the http://pgreca.it/app.php/example route. Regardless of which kind of redirect strategy was ultimately necessary to setup in order to make http://example.pgreca.it redirect to http://pgreca.it/app.php/example.

User avatar
PGreca
Registered User
Posts: 48
Joined: Mon Oct 29, 2018 12:36 pm
Location: Italy
Contact:

Re: App.php - Rewrite subdomain

Post by PGreca »

EA117 wrote:
Wed Oct 30, 2019 3:27 pm
The additional subdomains like http://example.pgreca.it may be able to be configured to point to the same document root as the http://pgreca.it/ site, and therefore you would control the redirects through the same .htaccess file. If you can configure them all to point to this same document root, then you will only need to edit the .htaccess file in your phpBB directory to setup the subdomain redirects. i.e. Requests for both http://pgreca.it/ and for http://example.pgreca.it/ would pass through that same single .htaccess file, and you would create the rules needed to rewrite the http://example.pgreca.it/ request or other subdomain requests within that single .htaccess file.
At the moment my website is hosted in a shared host.
It give me a possibility to create the "jolly subdomain", so i setted

Code: Select all

* IN CNAME pgreca.it.
When i visit "http://example.pgreca.it/", it return me the root of domain (pgreca.it/index.php).
Now how can i pass the value of "app.php" (app.php/example)?

User avatar
EA117
Registered User
Posts: 1368
Joined: Wed Aug 15, 2018 3:23 am
Contact:

Re: App.php - Rewrite subdomain

Post by EA117 »

PGreca wrote:
Wed Oct 30, 2019 5:38 pm
It give me a possibility to create the "jolly subdomain", so i setted

Code: Select all

* IN CNAME pgreca.it.
When i visit "http://example.pgreca.it/", it return me the root of domain (pgreca.it/index.php).
Now how can i pass the value of "app.php" (app.php/example)?
That does sound as though the web server configuration is allowing for the additional subdomain, or isn't configured to care about the request domain. Meaning the existing .htaccess on the http://pgreca.it/ site may be able to handle all the redirection needs.

It will require using a RewriteRule instead of a simple redirect in order to determine "was the request for pgreca.it versus example.pgreca.it?" See whether adding a RewriteRule such as this one is able to perform the redirect you're intending:

Code: Select all

RewriteCond %{HTTP_HOST} ^example.pgreca.it$ [NC]
RewriteRule ^(.*)$ https://pgreca.it/app.php/example [R=301,NC,L]
Place this rule anywhere after the RewriteEngine On statement, but before the phpBB default RewriteRule ^(.*)$ app.php [QSA,L] rule.

User avatar
PGreca
Registered User
Posts: 48
Joined: Mon Oct 29, 2018 12:36 pm
Location: Italy
Contact:

Re: App.php - Rewrite subdomain

Post by PGreca »

Ok, work it and i have setted for jolly subdomain.
But if i want the url remain "example.pgreca.it" how i can do?

I have read to remove the full url and set only the page

Code: Select all

RewriteRule ^(.*)$ https://pgreca.it/leagueoflegends/ [R=301,NC,L]
will be

Code: Select all

RewriteRule ^(.*)$ / [R=301,NC,L]
But it make an infinite redict loop

User avatar
EA117
Registered User
Posts: 1368
Joined: Wed Aug 15, 2018 3:23 am
Contact:

Re: App.php - Rewrite subdomain

Post by EA117 »

PGreca wrote:
Thu Oct 31, 2019 10:05 am
But if i want the url remain "example.pgreca.it" how i can do?
To confirm, do you mean that when a user enters https://example.pgreca.it/ in their web browser, you want the user to receive the HTML document generated by rewriting this URL to https://pgreca.it/app.php/example, but you do not want the URL seen in the user's web browser to change? Meaning, you want the user to still see https://example.pgreca.it/, correct?

Since you have both https://example.pgreca.it/ and https://pgreca.it/ pointed to the same document root, and controlled using the same .htaccess file, you should be able to achieve this by not issuing a redirect back to the user's web browser. Meaning instead of the "R=301" to have the web browser re-request the new URL, simply omit that "R" part in the rule:

Code: Select all

RewriteCond %{HTTP_HOST} ^example.pgreca.it$ [NC]
RewriteRule ^(.*)$ https://pgreca.it/app.php/example [NC,L]
Without issuing the redirect, the URL has been re-written "internally" within the web server, but the web server continues on and will deliver the content from the re-written URL. But the user's web browser is still seeing that the URL they requested was https://example.pgreca.it/.

PGreca wrote:
Thu Oct 31, 2019 10:05 am
I have read to remove the full url and set only the page

Code: Select all

RewriteRule ^(.*)$ https://pgreca.it/leagueoflegends/ [R=301,NC,L]
will be

Code: Select all

RewriteRule ^(.*)$ / [R=301,NC,L]
But it make an infinite redict loop
Agreed, that rule would cause a redirect loop. But I am not clear on what the actual intention is.

Is https://pgreca.it/leagueoflegends/ another example of a path you intend to handle through APP.PHP? Meaning the folder /leagueoflegends does not actually exist on the web server, and so you are expecting the web server to actually rewrite this URL to https://pgreca.it/app.php/leagueoflegends/ ?

Is https://pgreca.it/leagueoflegends/ a path you expected the user might enter from their web browser, or is this a result of the user entering https://leagueoflegends.pgreca.it/ ?


Maybe now is also the time to ask: What to you intend to show the user, once their URL has been re-written to send a route through APP.PHP? Meaning, are you creating an extension that handles the "/app.php/example" path and will show that user unique content? Or are you intending to simply show them a specific phpBB forum that exists on your site; meaning you simply want the user entering https://example.pgreca.it/ to be taken directly into the forum named "Example"?

User avatar
PGreca
Registered User
Posts: 48
Joined: Mon Oct 29, 2018 12:36 pm
Location: Italy
Contact:

Re: App.php - Rewrite subdomain

Post by PGreca »

EA117 wrote:
Thu Oct 31, 2019 12:11 pm


To confirm, do you mean that when a user enters https://example.pgreca.it/ in their web browser, you want the user to receive the HTML document generated by rewriting this URL to https://pgreca.it/app.php/example, but you do not want the URL seen in the user's web browser to change? Meaning, you want the user to still see https://example.pgreca.it/, correct?
Yes, i want when a user enters in "https://example.pgreca.it/" show the content of "https://pgreca.it/example/".
EA117 wrote:
Thu Oct 31, 2019 12:11 pm
Maybe now is also the time to ask: What to you intend to show the user, once their URL has been re-written to send a route through APP.PHP? Meaning, are you creating an extension that handles the "/app.php/example" path and will show that user unique content? Or are you intending to simply show them a specific phpBB forum that exists on your site; meaning you simply want the user entering https://example.pgreca.it/ to be taken directly into the forum named "Example"?
I' m trying to build a little portal with different categories.
Some extensions use the "app.php" for display their info, and for my portal i want divide them with the subdomains.

User avatar
EA117
Registered User
Posts: 1368
Joined: Wed Aug 15, 2018 3:23 am
Contact:

Re: App.php - Rewrite subdomain

Post by EA117 »

Okay. Because you've tested and seen "When i visit http://example.pgreca.it/, it return me the root of domain (pgreca.it/index.php)", then I think you should be able to get the result described by omitting the "R=301" out of the rule, as previously shown:

Code: Select all

RewriteCond %{HTTP_HOST} ^example.pgreca.it$ [NC]
RewriteRule ^(.*)$ https://pgreca.it/app.php/example [NC,L]
The https://example.pgreca.it/ URL that the user entered should be re-written into https://pgreca.it/app.php/example, but at the user's end they will still be seeing https://example.pgreca.it/ as the address in their web browser.

Post Reply

Return to “Extension Writers Discussion”