I have no idea how to achieve the following.
Currently I have a problem. Whenever a user goes to www.example.com or any link with same domain it will run a centralize.php (example). This PHP script will determine which PHP to call based on the links, something like centralized php files.
I tried to use .htaccess to achieve this without success. What am I doing wrong or is there are another way to do this?
RewriteEngine on
RewriteRule /(.*) /iindex4.php$1 [PT]
The above is what I've tried so far but it does't meet my requirement and is obviously flawed or buggy.
Question summary - navigate any url with same domain it will run a certain PHP file - is there another way to do this beside .htaccess
Try this:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
Then you can retrieve the requested URI from the script through the $_GET['q'] variable.
.htaccess is the way to do this, and this approach is commonly used, for instance by mediawiki, wordpress, and frameworks like Kohana.
To redirect everything to index.php:
RewriteEngine On
RewriteRule .* index.php/$0 [PT]
To allow existing files to be executed (which is not what you want, I guess):
RewriteEngine On
# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Rewrite all other URLs to index.php/URL
RewriteRule .* index.php/$0 [PT]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With