问题
I couldn't find exact answer to my question so I am posting this. Maybe it involves htaccess configuring.
What I would like is to have http://www.example.com/static_folder/dynamic_parameter
the above url should run the index.php in static_folder and I should be able to get that dynamic_parameter and output accordingly.
How to achieve this?
Thanks.
回答1:
A littlebit of htaccess can do it pretty easily. As for example, save this rule in the root directory's htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^/static_folder/index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /static_folder/index.php [L]
</IfModule>
Then use $_SERVER['REQUEST_URI'] inside /static_folder/index.php to get the dynamic_parameter.
Is it what you are trying to achieve?
回答2:
Try this in your .htaccess file:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
then you can do:
sudo a2enmod rewrite
sudo service apache2 restart
Also check answers for this question: How to remove all .php extension from a dir and all of its subdirectories?
回答3:
I believe the OP asked for index.php inside static_folder to get the variable, so, something like this, should do the trick:
RewriteRule ^static_folder/([^/]+)$ static_folder/index.php?variable=1$ [NC,L]
来源:https://stackoverflow.com/questions/25176270/dynamic-url-in-php-without-filename