简体   繁体   中英

URL rewriting in PHP Codeigniter.

I am new to PHP and this piece of code is passed on to me, that is its not written by me. Link are defined like this in the code:

<a href="<?php echo ADMIN_URL;?>/schools/showschool/<?php echo $key;?>/"

So if I click on icon Show School it gives me http://localhost/schools/showschool/21323/ rather than http://localhost/admin.schools/schools/showschool/21323/

if I manually add admin.schools or write the code as

<a href="<?php echo ADMIN_URL;?>admin.schools/schools/showschool/<?php echo $key;?>/"

the URL it opens up fine.

I am assuming that <?php echo ADMIN_URL;?> where ADMIN_URL is defined somewhere plays a part. I cannot find it in config.php, route.php or .htaccess files.

Am I looking in the wrong files? If not, and it is missing then how and where do I define ADMIN_URL ?

Open your SSH Terminal (like putty.exe) and run the following command

grep -R ADMIN_URL /var/www/html

Where /var/www/html needs to be your server root folder. The Terminal will then print the location in where the ADMIN_URL is defined and you can change it from there usually it is defined in the constants.php

Change the statment to:

define('ADMIN_URL', '/admin.schools/');

Why don't you try $_SERVER['SERVER_NAME'] instead of ADMIN_URl .

You can also use $_SERVER['HTTP_REFERER']

在 codeigniter 中使用 base_url() 获取根路径

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM