Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/cmake/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法隐藏.php扩展名。只有当我手动输入url时,它才能工作,如何用.htaccess修复它_Php_.htaccess_Redirect - Fatal编程技术网

无法隐藏.php扩展名。只有当我手动输入url时,它才能工作,如何用.htaccess修复它

无法隐藏.php扩展名。只有当我手动输入url时,它才能工作,如何用.htaccess修复它,php,.htaccess,redirect,Php,.htaccess,Redirect,我的问题是,当我键入不带.php扩展名的URL时(如https://example.com/register)它工作了,但当我单击“注册”时,它会重定向到https://example.com/register.php。我正在尝试编辑.htaccess文件,以便在默认情况下,当我单击register链接时,URL应该没有.php扩展名 我的爸爸.htaccess文件代码是 Options +MultiViews RewriteEngine On RewriteCond %{HTTPS} off

我的问题是,当我键入不带
.php
扩展名的URL时(如
https://example.com/register
)它工作了,但当我单击“注册”时,它会重定向到
https://example.com/register.php
。我正在尝试编辑
.htaccess
文件,以便在默认情况下,当我单击register链接时,URL应该没有
.php
扩展名

我的爸爸
.htaccess
文件代码是

Options +MultiViews
RewriteEngine On 
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
试试这个htaccess

RewriteEngine On

# Unless directory, remove trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/$ http://example.com/folder/$1 [R=301,L]

# Redirect external .php requests to extensionless url
RewriteCond %{THE_REQUEST} ^(.+)\.php([#?][^\ ]*)?\ HTTP/
RewriteRule ^(.+)\.php$ http://example.com/folder/$1 [R=301,L]

# Resolve .php file for extensionless php urls
RewriteRule ^([^/.]+)$ $1.php [L]
如果不起作用,请使用另一个

RewriteEngine On
# remove the index file
RewriteCond %{THE_REQUEST} ^.*/index
RewriteRule ^(.*)index$ http://www.example.org/$1 [R=301,L]  

# remove the .php extension 
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(([^/]+/)*[^.]+)$ $1.php [L]

# redirect from .php to less php
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /([^/]+/)*[^.#?\ ]+\.php([#?][^\ ]*)?\ HTTP/
RewriteRule ^(([^/]+/)*[^.]+)\.php http://www.example.org/$1 [R=301,L]
试试这个htaccess

RewriteEngine On

# Unless directory, remove trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/$ http://example.com/folder/$1 [R=301,L]

# Redirect external .php requests to extensionless url
RewriteCond %{THE_REQUEST} ^(.+)\.php([#?][^\ ]*)?\ HTTP/
RewriteRule ^(.+)\.php$ http://example.com/folder/$1 [R=301,L]

# Resolve .php file for extensionless php urls
RewriteRule ^([^/.]+)$ $1.php [L]
如果不起作用,请使用另一个

RewriteEngine On
# remove the index file
RewriteCond %{THE_REQUEST} ^.*/index
RewriteRule ^(.*)index$ http://www.example.org/$1 [R=301,L]  

# remove the .php extension 
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(([^/]+/)*[^.]+)$ $1.php [L]

# redirect from .php to less php
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /([^/]+/)*[^.#?\ ]+\.php([#?][^\ ]*)?\ HTTP/
RewriteRule ^(([^/]+/)*[^.]+)\.php http://www.example.org/$1 [R=301,L]

将此应用于htaccess文件

RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^([^.]+)$ $1.php [NC,L]

它适用于所有(.php或no.php)

将其应用于htaccess文件

RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^([^.]+)$ $1.php [NC,L]
它适用于所有(.php或no.php)


您已经启用了
MultiViews
(mod_协商的一部分),并且还尝试使用mod_rewrite追加文件扩展名。你应该做一个或另一个,而不是两个都做。他们做的事情本质上是一样的<代码>多视图可能会“获胜”,或者更糟的是,会造成冲突

您现有的代码基本上与以下代码相同:

Options +MultiViews
RewriteEngine On 
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

您已经启用了
MultiViews
(mod_协商的一部分),并且还尝试使用mod_rewrite追加文件扩展名。你应该做一个或另一个,而不是两个都做。他们做的事情本质上是一样的<代码>多视图可能会“获胜”,或者更糟的是,会造成冲突

您现有的代码基本上与以下代码相同:

Options +MultiViews
RewriteEngine On 
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

感谢大家的贡献,我为自己没有回复你们的宝贵努力而感到羞愧,因为我的老板给了我一个不同的项目

工作代码是 此外,还从中删除.php扩展名
页面的所有锚定标记。
你可以在这里查看

谢谢大家的贡献,我为自己没有回复你的宝贵努力而感到羞愧,因为我的老板给了我一个不同的项目

工作代码是 此外,还从中删除.php扩展名
页面的所有锚定标记。
您可以在这里查看

嗨,Ana,谢谢您的帮助,但它只对某些链接有效,而不是所有链接。不幸的是,一个链接被重定向到了我的根目录。这是最后一个代码更接近于解决问题,但它不能为登录后的页面(私人页面)工作,而是它阻止登录。嗨,Anand感谢帮助,但它的工作只是对一些链接,但不是所有的,不幸的是一个链接重定向到甚至我改变了我的根目录。这是最后一个代码更接近于解决问题,但它在登录后无法用于页面(对于私人页面),而是阻止登录。抱歉@Dev它甚至无法重定向到任何页面。抱歉@Dev它甚至无法重定向到任何页面。当您“单击
注册
链接”时,请求的URL是什么?如果这是您手动键入的相同URL,那么您确实应该得到相同的结果。当您“单击
注册
链接”时,请求的URL是什么?如果这是您手动键入的相同URL,那么您确实应该得到相同的结果。