0
我在StackOverflow上找到了很多解决方案来处理这个常见问题,但是似乎没有一个适用于我的设置。当我链接到一个PHP页面我仍然看到PHP扩展,并希望有重写规则以使用.htaccess删除.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'' 使用这个。 –
@ Abhishek。谢谢。是的,我们知道那个用例,但很好奇如何用.php扩展名修复所有页面。 – George