apache - using htaccess to remove .php from URL -


my url: http://localhost/test.php

i using:

.htaccess:

rewriteengine on  rewritebase / rewritecond %{request_filename} !-f  rewritecond %{request_filename} !-d rewriterule ^(.+)$ index.php?url=$1 [qsa,l] 

php:

$url = $_get['url']; echo var_dump($url); 

but $url is:null null null null null null

edit: adjusted handle both redirect , rewrite.

rewriteengine on  rewritebase /  # redirect .php urls rewritten urls rewritecond %{request_filename} !-f  rewriterule ^(.+)\.php$ $1 [l,qsa,r=301]  # rewrite urls processing router (index.php) rewritecond %{request_filename} !-f  rewriterule ^(.+)$ index.php?url=$1 [qsa,l,nc] 

you should exclude rewritecond %{request_filename} !-d condition, attempt access directory if url matches it. not desirable when doing url rewriting.

index.php

$url = isset($_get['url']) ? $_get['url'] : null; var_dump($url); 

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -