简体   繁体   中英

htaccess doesn't removing php extensions

I have a php project running. I am running my project on localhost . I want to remove php extensions from url in addressbar. I try several htaccess scripts but none worked some shows 404 not found error or doesn't work at all. directory where my php project is D:\\VertrigoServ\\www\\gotmation I am using this htaccess script

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[\s?] [NC]
# RewriteRule ^ %1 [R=301,L]
 RewriteRule ^([^\.]+)$ $1.php [NC,L] 

# To internally forward /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/gta/$1.php -f
# RewriteRule ^(.+?)/?$ /gta/$1.php [L]
RewriteRule ^([^\.]+)$ $1.php [NC,L] 

I am newbie php programmer doesn't have much experience of this stuff. Any help will be appreciated.

RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(.*)\.php
RewriteRule ^ /%1 [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

This must work... you might have any other issues... do you have permitted .htaccess in apache config file???

try:

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[\s?] [NC]
RewriteRule ^ /%1 [R=301,L]

# To internally forward /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(.+?)/?$ /$1.php [L]

These rules need to be in your document root .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM