【发布时间】:2017-01-07 08:38:45
【问题描述】:
我在 StackOverflow 上找到了许多解决这个常见问题的解决方案,但似乎没有一个适用于我的设置。当我链接到一个 php 页面时,我仍然看到 .php 扩展名并希望拥有
index.php updated to 'website'
about-us.php to be website/about
我正在使用文件夹“网站”内的 wamp / localhost 开发网站。我的 .htacces 文件位于“网站”文件夹的根目录中。
我试图用来从 index.php 和其他 php 页面中删除 .php 扩展名的重写条件/规则是这样的。
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
我的链接有这样的 URL
<a href="index.php">
<a href="about-us.php">
这是完整的 .htaccess 文件
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
## EXPIRES CACHING ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType text/css "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType application/x-javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 2 days"
</IfModule>
## EXPIRES CACHING ##
<IfModule mod_deflate.c>
# compress text, html, javascript, css, xml:
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
</IfModule>
# Or, compress certain file types by extension:
<files *.html>
SetOutputFilter DEFLATE
</files>
【问题讨论】:
-
这里你可以直接链接到
index而不是index.php<a href="index">使用这个。 -
@阿布舍克。谢谢。是的,我们知道那个用例,但很好奇如何修复所有带有 .php 扩展名的页面。
标签: .htaccess mod-rewrite localhost