我想对网站的网址做一些事情,我似乎无法查看.htaccess文件。
1删除文件扩展名f.e. example.com/file.php
应为example.com/file
2删除www。 F.E. www.example.com
应为example.com
(我已将此部分用于工作,但如果在我修复之后我又讨厌这个部分
3没有人应该能够在根f.e的末尾看到index.php。 example.com/index.php
应为example.com
4我的博客页面应该有很好的网址f.e. example.com/blog.php?article=the-name-of-article
应为example.com/blog/the-name-of-article
这是我当前的.htaccess文件
Options +FollowSymLinks -MultiViews
rewriteengine on
RewriteBase /
## Hide .php extension
## To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,NC]
## To internally redirect /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_URI}.php
## remove www
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
## remove ugly part of url for blog.php
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]
RewriteRule ^blog/(.*)$ blog.php?article=$1 [QSA,L]
当我尝试转到blog/the-name-of-article
时,我收到内部服务器错误。
答案 0 :(得分:0)
删除.php:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php [NC,L]
请参阅Remove .php extensions with .htaccess without breaking DirectoryIndex
修改强> 对于漂亮的网址,请查看本教程:http://net.tutsplus.com/tutorials/other/using-htaccess-files-for-pretty-urls/
答案 1 :(得分:0)
从您的.htaccess的正文和评论中看来我过去会提供它:P
你的.htaccess中唯一错误的是规则的排序。始终将它们从最具体到最通用。你的代码是这样的:
Options +FollowSymLinks -MultiViews
rewriteengine on
RewriteBase /
## remove www
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
## remove ugly part of url for blog.php
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]
RewriteRule ^blog/(.*)$ /blog.php?article=$1 [QSA,L]
## Hide .php extension
## To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,NC]
## To internally redirect /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_URI}.php