After accessing a URL without a query parameter, I want to automatically skip it to the URL with the query parameter attached.

Asked 2 years ago, Updated 2 years ago, 103 views

■ What you want to do (overview):
After accessing a URL without a query parameter, I want to automatically skip it to the URL with the query parameter attached.

■ What you want to do (details):
1. Currently, using query parameters, a program that can be displayed in DB collaboration is
Creating.

2. Specifically,
http://◎◎◎.php?lan=en

and in this case

Among the programs in ◎◎◎.php,

Extract "lan=en, that is, the language is English" from the DB and
I'm showing it.

3. Not surprisingly,
Simply
without query parameters If you have accessed http://◎◎◎.php, click
There is no normal display.

4. What you want to do:

Specifically,
If you have access to http://◎◎◎.php,

automatically,
http://◎◎◎.php&lan=en
 
I would like to display it by adding a query parameter.
Should I write it in .htaccess?

(Additional Questions)
·In the case of the method described in .htaccess, it is considered an effective method in terms of SEO countermeasures.
Is that so?
 
Thank you for your cooperation.

php mysql apache .htaccess

2022-09-30 14:17

1 Answers

Resolved!
Resolved by using the issu function instead of using the .htaccess file

■Conclusion
In the first line of the php file:

<?php 
$lan=isset($_GET['lan'])? $_GET ['lan']: 'en';
?>

■ Code Description
·Check query parameters by using the issu function
·Use the trinomial operator to create a neat code

■ PHP operation flow
◎ Pattern 1
http://example.com/XXX.php?lan=en

If accessed by , the query parameter is checked by using the issuet function, and since there is $_GET['lan'], the processing proceeds as $lan=$_GET['lan'].
In other words, http://example.com/XXX.php?lan=en URL as before

◎ Pattern 2

http://example.com/XXX.php
If accessed by the , check the query parameters by using the issuet function, and internally substitute the value as $lan='en'; because there is no $_GET['lan']

In this case, http://example.com/XXX.php appears as the URL, but
Internally, it is the same as accessing http://example.com/XXX.php?lan=en

This post is @Kim-chan's comment as a community wiki.


2022-09-30 14:17

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.