我在用这个代码
# Apache Rewrite Rules
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
# Add trailing slash to url
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/|#(.*))$
RewriteRule ^(.*)$ $1/ [R=301,L]
# Remove .php-extension from url
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^([^\.]+)/$ $1.php
# End of Apache Rewrite Rules
</IfModule>它不会对我的页面隐藏.php扩展,当我从锚标记中删除'.php‘时,页面就会被重定向。就像。如果url是www.example.com/mysite/store.php,并且当我从URI或锚点href中删除'.php‘时,新的url就变成了www.example.com/store/,而这个www.example.com/store/是不可用的。我试图手动输入url作为example.com/mysite/store,但它也是不可用的。
显然,.htaccess没有使用这些规则,如果我在那里写胡言乱语,得到一个500个服务器错误,所以.htaccess工作正常,但我做的是什么错误。
建议。谢谢你的建议!
更新
好吧,我已经想好了,我成功地完成了我的问题。但是我的引导文件完全失效了,我猜是因为它将'bootstrap.css‘链接为'bootstrap.css.php’,因为我现在使用的.htaccess文件是:
# Turn on the rewrite engine
RewriteEngine on
# If the request doesn't end in .php (Case insensitive) continue processing rules
RewriteCond %{REQUEST_URI} !\.php$ [NC]
# If the request doesn't end in a slash continue processing the rules
RewriteCond %{REQUEST_URI} [^/]$
# Rewrite the request with a .php extension. L means this is the 'Last' rule
RewriteRule ^(.*)$ $1.php [L]
DefaultType application/x-httpd-php
DirectoryIndex index.php index.html更新2
对不起,这不是我在上一次更新中提到的问题,因为在我删除了我的index.php中的引导链接之后,我得到了不同的结果。问题是:localhost/example/index.php是我的主页,但是本地主机/示例是在url中显示的。localhost/example是一个包含文件的目录。因此,应该作为localhost/example/image/logo.png加载的图像作为localhost/example/index.php/image/logo.png加载,这使得示例站点的行为很奇怪。
发布于 2016-05-05 10:36:16
核对已张贴的答案:
Remove .php extension with .htaccess
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !\.(?:css|js|jpe?g|gif|png)$ [NC]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ $1.php [NC,L]https://stackoverflow.com/questions/37047848
复制相似问题