Reputation: 43
I need some suggestion on some htaccess rule. What I want is that all requests in my site will redirect to index.php. But also I need to log what url the user was trying to visit in my databse. So, say if someone try to visit a page in my site(which does not exists) like
example.com/somefolder/somefile.php?somevar=someval&somevar2=someval2
then he will actually be redirected to index.php where I will need to somehow get and log the original full url in my database.
Hope I was able to clear my clear my requirement. Thanks.
Upvotes: 1
Views: 120
Reputation: 65
The above answer didn't work in my case so after a research I found this helpful and might be helpful for someone else too in future.
To redirect all requests to index.php
, provide these lines in .htaccess
file
RewriteEngine on
RewriteCond %{REQUEST_URI} !/index.php$
RewriteRule (.*) /index.php [R=301,L]
Remember this redirects all requests to index.php
even if its your stylesheet.css or jquery.js
Upvotes: 0
Reputation: 786091
Put this code in your DOCUMENT_ROOT/.htaccess
file:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . /index.php [L]
Original URL is available to you in $_SERVER['REQUEST_URI']
Upvotes: 1