0

我想从 URL 中删除网页扩展,有人给了我 .htaccess 的代码。但是当我打开重写模块时它可以在 localhost一些访问 example.com/cool.php 到 example.com/cool.... 以及关于 godaddy 重写模块的帮助 我联系了他们,他们还没有回复我。下面是那个人给我的代码..谢谢

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]
4

1 回答 1

1

假设您想显示“漂亮”的 URL ( 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
于 2013-04-14T07:33:29.547 回答