htaccess:如何删除除index.php之外的php扩展名?param=
我想要这些规则:htaccess:如何删除除index.php之外的php扩展名?param=,php,.htaccess,Php,.htaccess,我想要这些规则: /字符串smth与index.php匹配?param=string smth /某些文件带有破折号匹配 some-file-with-dashes.php /some-file-with-dashes.php删除.php扩展名 延伸 php重定向到/ 这在我的本地机器上有效,但在服务器上无效。apache配置是否有一些选项/标志或其他东西需要更改以支持此功能 这是我当前的.htaccess文件 RewriteCond %{REQUEST_FILENAME} !-d Rewrit
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)$ $1.php [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?param=$1 [QSA,NC,L]
RewriteCond %{THE_REQUEST} ^.*/index\.php
RewriteRule ^(.*)index.php$ /$1 [R=302,L]
在我的本地机器上,除了规则#3(我没有在.htaccess中实现)之外,这是有效的
在我的服务器上(数字海洋,ubuntu):
- 匹配(规则1)
- 打开文件
- 对404的答复
- 因此,答案的一部分在@Martin建议的修复中
至于其他方面:
# remove .php
RewriteCond %{REQUEST_URI} !^/(index|url)\.php
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^\ ]+)\.php
RewriteRule ^/?(.*)\.php$ /$1 [L,R=302]
# match .php if exists
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^/?(.*)$ /$1.php [L]
^(.*)$
为什么这里有一个?
呢?调整一下:^(.*)$/index.php
谢谢,这修复了2。规则。当直接访问/auto-karta-hrvatske.php时,是否有办法删除“.php”(规则3)?请参阅