Ok, I use PHP for my website without any framework ( I'm new ), So I saw many websites that are something like this :
example.com/example?example1=example2
My question is how can I do that to my website? I removed index.php
from my addresses but my website shows requests like this :
myweb.com/myweb/?example1=example2
I simply want to remove /
before ?
mark. What should I do ? Thank your for your help :)
EDIT* : Also Is there a way to permanently remove .php
extension from all of my php files (index.php
and example.php
)
Here is my .htaccess
file content :
Options FollowSymLinks -MultiViews
Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1 [L,QSA]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s(.*)/index\.php [NC]
RewriteRule ^ %1 [R=301,L]
CodePudding user response:
This code also removes all .php extensions. You can modify it to redirect them to some error page on your website.
Options FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
## hide .php extension
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.] )\.php [NC]
RewriteRule ^ %1 [R=302,L]
# To internally forward /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ $1.php [L]