【问题标题】:What all do I need in my .htaccess, such as permissions, etc我的 .htaccess 中需要什么,例如权限等
【发布时间】:2014-05-10 14:28:44
【问题描述】:

我的网站根目录中有一个.htaccess 文件,并且我确定.htaccess 扩展名,而不是.htaccess.txt。我正在尝试清理我的 .php 网址,即使在查看了有关此问题的所有其他问题之后,它也无法正常工作。

我非常确定删除扩展的代码是正确的,所以我想知道.htaccess 中是否还有其他代码需要我获得权限或类似的东西。感谢您提供任何答案,不要将其标记为duplicate... 我在 Stack Overflow、SitePoint 和所有其他网站上搜索了几个小时。

这是我的.htaccess 中的唯一代码:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_URI} !/$
RewriteRule ^(.*)$ $1\.php

只是为了确保清楚,我想要网址:

website.com/about.php
website.com/home.php
website.com/blog.php

看起来像

website.com/about
website.com/home
website.com/blog

它应该从我网站的所有目录中的 ALL .php 文件中删除 .php

【问题讨论】:

  • 你期望重写规则能做什么?

标签: .htaccess mod-rewrite permissions root


【解决方案1】:

你真的想要

RewriteEngine On

#if the requested file doesn't exist on server filesystem
RewriteCond %{REQUEST_FILENAME} !-f 

#AND if the file with php extension exists. Just an extra check
RewriteCond %{REQUEST_FILENAME}\.php -f 

#AND if the request isn't for domain root
RewriteCond %{REQUEST_URI} !/$ 

RewriteRule ^(.*)$ /$1\.php?r=1 [L]

#redirect all urls ending with .php to "clean" URL
RewriteCond %{REQUEST_URI} ^/?(.*)\.php$
RewriteCond %{QUERY_STRING} !(^|&)r=1
RewriteRule ^(.*)\.php$  /$1? [L,R=301]

它不会使website.com/about.php 看起来像website.com/about,但如果用户访问website.com/about,它将显示website.com/about.php

【讨论】:

  • 这就是我现在正在寻找的。我不希望它显示.php 扩展
  • 你试过重写规则了吗?
  • 我希望它显示website.com/about,即使他们输入website.com/about.php,而不是相反。
猜你喜欢
  • 2011-02-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-09-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多