如何从URL中删除网页的扩展?网页、URL

2023-09-02 09:51:09 作者:【零碎的记忆】

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

  RewriteEngine叙述上
的RewriteBase /

#删除输入code here.php;使用THE_REQUEST至prevent无限循环
的RewriteCond%{THE_REQUEST} ^ GET (。*)。PHP  HTTP
重写规则(。*)。PHP的$ $ 1 [R = 301]


#删除索引
重写规则(。*)/指数$ $ 1 / [R = 301]

#删除斜线,如果没有目录
的RewriteCond%{} REQUEST_FILENAME!-d
的RewriteCond%{REQUEST_URI} / $
重写规则(。*)/ $ 1 [R = 301]

#添加的.php访问文件,但不重定向
的RewriteCond%{} REQUEST_FILENAME -f .PHP
的RewriteCond%{REQUEST_URI}!/ $
重写规则(。*)$ 1  .PHP [L]
 

解决方案

假设你要显示的pretty的URL(example.com/cool )但仍获得原始请求( example.com/cool.php ),您可以尝试这种在根目录下的.htaccess文件中的数据:

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

 选项+了FollowSymLinks -MultiViews
RewriteEngine叙述上
的RewriteBase /

#直接从THE_REQUEST变量获取的URI路径
的RewriteCond%{THE_REQUEST} ^(GET | HEAD) S /  PHP [NC](*)。
#剥开扩展和重定向永久
重写规则。* /%2 [R = 301,L,NC]

#现在,在浏览器的地址栏中显示:http://example.com/cool

的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d
的RewriteCond%{REQUEST_URI}!。PHP [NC]
#内部映射到原始资源
重写规则^(。*)/? /$1.php [L,NC]

#地图默默地为:http://example.com/cool.php
 

网页 URL 错误,无法打开,是什么问题

I want to remove webpage extension from URL,somebody gave me the code for .htaccess. But it works on localhost when I turn on rewrite module.But when I use it on Godaddy it doen't work.and also when I visit example.com/cool.php it says 404 not found But I want it to be redirect if some visit example.com/cool.php to example.com/cool.... and also help about godaddy rewrite module I contacted them they haven't replied me yet. Here below is the code the guy gave to 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]

解决方案

Assuming you want to show the "pretty" URL (example.com/cool) but still get the data from the original request (example.com/cool.php), you may try this in the .htaccess file at root directory:

Updated to work with php files at any directory:

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