3

How can I take all requests to www.myurl.com/{ANYTHING} and send them all to www.myurl.com/index.php

I am finding I can send everything with:

RewriteRule .* index.php [R=Permanent,L]

This works great, except I am redirected to www.myurl.com/home/username/public_html because of my cpanel/apache installation. So instead I changed my code to

RewriteBase /
RewriteRule .* index.php [R=Permanent,L]

But this causes the infinite loop again.

dacopenhagen
  • 2,414
  • 2
  • 23
  • 29

4 Answers4

2

Try:

RewriteCond %{REQUEST_URI} !^/index.php
RewriteRule .* /index.php [R=Permanent,L]
Jon Lin
  • 142,182
  • 29
  • 220
  • 220
  • This seems to redirect everything to index.php, but using phpinfo() inside of index.php shows that there is no way to obtain the original URL. So this redirects, but the original URL is lost. – David Spector Jan 01 '20 at 23:29
0

With Apache, use mod_rewrite:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?q=$1 [L,QSA]
Meetai.com
  • 6,622
  • 3
  • 31
  • 38
0

.htaccess

RewriteEngine On
RewriteCond %{REQUEST_URI} !.*\.(png|jpg|css|js)$ [NC]
RewriteRule ^(.*)$ index.php?URL=$1 [NC,L,QSA]

OR

/etc/apache2/sites-available/site.conf

<Directory /var/www/html>
        RewriteEngine On
        RewriteCond %{REQUEST_URI} !.*\.(png|jpg|css|js)$ [NC]
        RewriteRule ^(.*)$ index.php?URL=$1 [NC,L,QSA]
</Directory>
-1

This effectively sends me to index.php without causing a loop.

RewriteCond %{REQUEST_URI} ^/index\.php$
RewriteRule ^(.*)$ - [L]

RewriteRule ^(.*)$ /index.php?url=%{REQUEST_URI} [R=302,L,QSA]
dacopenhagen
  • 2,414
  • 2
  • 23
  • 29