Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/475.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 将所有请求重定向到index.php并在页面上显示URL_Javascript_.htaccess - Fatal编程技术网

Javascript 将所有请求重定向到index.php并在页面上显示URL

Javascript 将所有请求重定向到index.php并在页面上显示URL,javascript,.htaccess,Javascript,.htaccess,我正在尝试将所有请求重定向到index.php,并在页面上显示URL .htaccess文件 RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule . index.php [L] index.php文件 <!DOCTYPE html> <html> <head> <script ty

我正在尝试将所有请求重定向到index.php,并在页面上显示URL

.htaccess文件

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php [L]
index.php文件

<!DOCTYPE html>
<html>
    <head>
        <script type="text/javascript" src="assets/libs/js/jquery-1.11.3.min.js"></script>
        <script type="text/javascript">
            $(function() {
                document.getElementById("body").innerHTML = window.location.pathname;
            })();
        </script>
    </head>
    <body id="body"></body>
</html>

$(函数(){
document.getElementById(“body”).innerHTML=window.location.pathname;
})();
当我转到localhost/test时,一切正常,“/test”显示在页面上,但是,如果我转到
localhost/test/anythinghere
,页面上什么也不显示。我希望发生的事情的一个示例:
“/test/anything/you/are/cool”
如果我转到
localhost/test/anything/you/are/cool
,将显示在页面上


编辑:我解决了这个问题,谢谢。

这是因为你把它放在了.htaccess中,而这只会影响文件夹。。。您必须将其放在/etc/apache2/sites available/your-site.conf中

<VirtualHost *:8888 *:80>
  DocumentRoot /var/www/help/
  ServerName help.com

  <Directory /var/www/help/>
    Options FollowSymLinks
    AllowOverride All
    AddDefaultCharset utf-8

    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ /index.php/$1 [L]
  </Directory>
</VirtualHost>

DocumentRoot/var/www/help/
ServerName help.com
选项如下符号链接
允许超越所有
AddDefaultCharset utf-8
重新启动发动机
重写cond%{REQUEST_FILENAME}-D
重写cond%{REQUEST_FILENAME}-F
重写规则^(.*)$/index.php/$1[L]
也检查我的重写规则

我在说我的重写。。。“如果找不到文件夹或文件,请转到index.php”。这是有道理的,因为我把它放在虚拟主机中


您正在尝试执行相同的操作,但是.htaccess控制着他的文件夹。

您可以在.htaccess正则表达式上尝试此变体吗,Matt。这对我很有用:

RewriteEngine on
RewriteCond  %{REQUEST_FILENAME}   !-f
RewriteCond  %{REQUEST_FILENAME}   !-d
RewriteRule  ^(.*)$  index.php/$1  [L]

这个对你有效,但OP的代码不起作用?我觉得这不太可能。我在两台不同的机器上试过,但都没用。