douhui8025 2019-05-03 08:12
浏览 46

URL目录作为URL中的变量保留目录传递给PHP

I have been attempting to use mod_rewrite to pass an invalid URL directory as a variable to PHP scripts but remain in the URL.

Example:

http://my.test.com/mydir redirects to http://my.test.com/index.php?dir=mydir but URL shows http://my.test.com/mydir

and

http://my.test.com/mydir/example.php redirects to http://my.test.com/example.php but URL displays http://my.test.com/mydir/example.php

This will be for many PHP scripts that would keep the directory in the URL. I need the css/js/imgs directories to still be accessible. I believe I can do this using the base href in my html head. I am trying to keep the invalid directory in the URL at all times.

With my current example if I call

http://my.test.com/mydir

it displays the index.php and the URL stays the same. If I call

http://my.test.com/mydir/index.php it gives me a 404 error.

I have tried every example on stack overflow as well as too many to count from Google searches. I figure after two days trying I need to get a little help.

My .htaccess:

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/\.]+)/?$ index.php?c=$1 
RewriteRule ^([^/\.]+)/([^/\.]+)?$ index.php?url=$2&c=$1 [L]

My index.php I am using for testing:

<?php

if (isset($_GET['c'])) {
  $companyid = $_GET['c'];
}
if (isset($_GET['url'])) {
  $url = $_GET['url'];
}

echo "DEBUG: " . $companyid . "<br>";
echo "DEBUG: " . $url;
exit;

?>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 linux驱动,linux应用,多线程
    • ¥20 我要一个分身加定位两个功能的安卓app
    • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
    • ¥15 IAR程序莫名变量多重定义
    • ¥15 (标签-UDP|关键词-client)
    • ¥15 关于库卡officelite无法与虚拟机通讯的问题
    • ¥15 目标检测项目无法读取视频
    • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
    • ¥100 求采集电商背景音乐的方法
    • ¥15 数学建模竞赛求指导帮助