如何从URL中移除网页扩展? [关闭](How to remove webpage extens

2019-08-22 22:16发布

我想删除从URL网页的扩展,有人给了我的.htaccess的代码。 但它工作在本地主机上,当我打开改写module.But当我使用它在Godaddy的它doen't work.and还当我访问example.com/cool.php它说404没有找到,但我希望它是,如果重定向一些访问example.com/cool.php到example.com/cool ....也有利于有关godaddy的重写模块我联系他们,他们还没有回答我呢。 这里是下面的家伙给了me..Thanks代码

RewriteEngine On
RewriteBase /

# remove enter code here.php; use THE_REQUEST to prevent infinite loops
RewriteCond %{THE_REQUEST} ^GET\ (.*)\.php\ HTTP
RewriteRule (.*)\.php$ $1 [R=301]


# remove index
RewriteRule (.*)/index$ $1/ [R=301]

# remove slash if not directory
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} /$
RewriteRule (.*)/ $1 [R=301]

# add .php to access file, but don't redirect
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_URI} !/$
RewriteRule (.*) $1\.php [L]

Answer 1:

假设你要显示的“漂亮”的网址( example.com/cool ),但仍从原始请求(数据example.com/cool.php ),你可能会在根目录下的.htaccess文件试试这个:

更新在任何目录下的PHP文件的工作:

Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteBase /

# Get the URI-path directly from THE_REQUEST variable
RewriteCond %{THE_REQUEST} ^(GET|HEAD)\s/(.*)\.php [NC]
# Strip the extension and redirect permanently
RewriteRule  .*   /%2   [R=301,L,NC]

# Now the browser's address bar shows: http://example.com/cool

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !\.php  [NC]
# Map internally to the original resource
RewriteRule  ^(.*)/?   /$1.php  [L,NC]

# Maps silently to: http://example.com/cool.php


文章来源: How to remove webpage extension from URL? [closed]