I'm using apache2 and latest php what I want to do is load a random URL php file on my domain.
Example: example.com/randfilename.php?var1=1&var2=2&var3=3
Then the randomfilename.php will load file.php with vars. Keep in mind randomfilename.php will not be that name is will be random with .php at the end.
I tried with RewriteEngine and it only works for me for example.com/randfilename but once I add .php it doesn't work.
What I have tried is
RewriteEngine On
RewriteRule ^([a-zA-Z\-]+)$ file.php?key=$1 [L]
Is there another away of doing this to achieve what I'm trying to do.
The .php extension has a . in it, and your pattern is ^([a-zA-Z\-]+)$, which matches only letters and dashes, no periods. You can explicitly add the .php extension to the pattern and exclude file.php:
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/file\.php$
RewriteRule ^([a-zA-Z\-]+)\.php$ file.php?key=$1 [L]
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