为什么这个重写不起作用? Htaccess调整 [英] Why this rewriterule is not working? Htaccess tuning

查看:87
本文介绍了为什么这个重写不起作用? Htaccess调整的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我正在尝试删除我正在工作的网站中所有页面的扩展名。



我把它写入.htaccess文件:



 RewriteEngine on 
RewriteCond%{REQUEST_FILENAME}!-f
RewriteCond%{REQUEST_FILENAME}!-d
RewriteRule(。*)/ base /404.php [L]
RewriteRule ^(。+ [^ / ])/ $ http://%{HTTP_HOST} / $ 1 [R = 301,L]

#from http://whatever.com to http://www.whatever.com
RewriteCond%{HTTP_HOST} ^ whatever.com $
RewriteRule ^ /?$http \:\ / \ / www \ .whatever\.com \ /[R = 301, L]

#尝试删除php扩展名
RewriteCond%{REQUEST_FILENAME}!-f
RewriteCond%{REQUEST_FILENAME} .php -f
RewriteRule ^(。 *?)/?$ / $ 1.php [L]





代码的第一部分有效,但当我尝试删除时它没有的PHP扩展。



我想从文件中删除扩展名我在浏览器中显示...据说它使得攻击变得更加困难,但真正重要的原因是它似乎对页面的seo来说是一件好事...



有什么方法可以完成这项工作吗?



我尝试了一些互联网示例,但我无法让它工作。



任何提示?



谢谢!



我尝试了什么:



使用我在互联网上找到的各种片段,但这些片段没有用。 ..

解决方案

http://%{HTTP_HOST} /


1 [R = 301,L]

#从http://whatever.com转到http://www.whatever.com
RewriteCond%{HTTP_HOST} ^ whatever.com


RewriteRule ^ /?

Hello all,

I'm trying to remove the extensions of all the pages in a web site I'm working.

I've written this into the .htaccess file:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) /base/404.php [L]
RewriteRule ^(.+[^/])/$ http://%{HTTP_HOST}/$1 [R=301,L]

#from http://whatever.com to http://www.whatever.com
RewriteCond %{HTTP_HOST} ^whatever.com$
RewriteRule ^/?$ "http\:\/\/www\.whatever\.com\/" [R=301,L]

#Try to remove the php extensions
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ /$1.php [L]



The first part of the code works, but when I try to remove the php extensions it doesn't.

I would like to remove the extension from the filename it's shown in the browser... supposedly it makes it more difficult to get hacked, but the truly important reason is that it seems that it is a good thing for the seo of the page...

Is there any way to get this done?

I've tried some internet examples but I can't get it to work.

Any hint?

Thank you!

What I have tried:

Using various snippets that I've found in the Internet but that have not worked...

解决方案

http://%{HTTP_HOST}/


1 [R=301,L] #from http://whatever.com to http://www.whatever.com RewriteCond %{HTTP_HOST} ^whatever.com


RewriteRule ^/?


这篇关于为什么这个重写不起作用? Htaccess调整的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆