简体   繁体   中英

Redirecting all requests to index.php and displaying the URL on the page

I'm trying to redirect all requests to index.php and display the URL on the page.

.htaccess file;

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

index.php file;

<!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>

When I go to localhost/test, everything works perfectly, "/test" is displayed on the page, however, if I go to localhost/test/anythinghere , nothing is displayed on the page. An example of what I want to happen: "/test/anything/you/are/cool" to be displayed on the page if I go to localhost/test/anything/you/are/cool .

EDIT: I fixed the issue, thanks.

Its because you put that in a .htaccess, and that affects only the folder... you must put that in /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>

Check my rewrite rule too.

Im saying with my rewrites... "if you cannot find the folder nor the file, go to index.php". It makes sense because Im putting that in the virtualhost...

You are trying to do the same, but .htaccess its controling his folder.

Could you try this variation on the .htaccess Regex, Matt. It works for me:

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

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