找回密码
 立即注册

typecho开启伪静态,去掉那个讨厌的index.php

2022-7-24 14:48:39 · 站长社区
Typecho后台设置永久链接后,会在域名后加上index.php,很多人都接受不了。例如如下网址:https://www.域名.com/index.php/archives/37/,但我们希望最终的形式是这样:https://www.域名.com/archives/2514.html。那么我们如何做到这样的效果?
1.配置服务器的rewrite规则
如果在保存上述配置的时候,typecho无法自动配置,那么你可能需要手动配置服务器的rewrite规则。
Linux Apache 环境 (.htaccess):
  1. <IfModule mod_rewrite.c>
  2. RewriteEngine On
  3. # 下面是在根目录,文件夹要修改路径
  4. RewriteBase /
  5. RewriteCond %{REQUEST_FILENAME} !-f
  6. RewriteCond %{REQUEST_FILENAME} !-d
  7. RewriteRule ^(.*)$ /index.php/$1 [L]
  8. </IfModule>
复制代码

Linux Apache 环境(Nginx):
  1. location / {
  2. index index.html index.php;
  3. if (-f $request_filename/index.html) {
  4. rewrite (.*) $1/index.html break;
  5. }
  6. if (-f $request_filename/index.php) {
  7. rewrite (.*) $1/index.php;
  8. }
  9. if (!-f $request_filename) {
  10. rewrite (.*) /index.php;
  11. }
  12. }
复制代码
Windows IIS 伪静态 (httpd.ini):
  1. [ISAPI_Rewrite]
  2. # 3600 = 1 hour
  3. CacheClockRate 3600
  4. RepeatLimit 32
  5. # 中文tag解决
  6. RewriteRule /tag/(.*) /index\.php\?tag=$1
  7. # sitemapxml
  8. RewriteRule /sitemap.xml /sitemap.xml [L]
  9. RewriteRule /favicon.ico /favicon.ico [L]
  10. # 内容页
  11. RewriteRule /(.*).html /index.php/$1.html [L]
  12. # 评论
  13. RewriteRule /(.*)/comment /index.php/$1/comment [L]
  14. # 分类页
  15. RewriteRule /category/(.*) /index.php/category/$1 [L]
  16. # 分页
  17. RewriteRule /page/(.*) /index.php/page/$1 [L]
  18. # 搜索页
  19. RewriteRule /search/(.*) /index.php/search/$1 [L]
  20. # feed
  21. RewriteRule /feed/(.*) /index.php/feed/$1 [L]
  22. # 日期归档
  23. RewriteRule /2(.*) /index.php/2$1 [L]
  24. # 上传图片等
  25. RewriteRule /action(.*) /index.php/action$1 [L]
复制代码
nginx 配置
  1. server {
  2.         listen          80;
  3.         server_name     yourdomain.com;
  4.         root            /home/yourdomain/www/;
  5.         index           index.html index.htm index.php;

  6.         if (!-e $request_filename) {
  7.             rewrite ^(.*)$ /index.php$1 last;
  8.         }

  9.         location ~ .*\.php(\/.*)*$ {
  10.             include fastcgi.conf;
  11.             fastcgi_pass  127.0.0.1:9000;
  12.         }

  13.         access_log logs/yourdomain.log combined;
  14.     }
复制代码

apache 配置
  1. <IfModule mod_rewrite.c>
  2.     RewriteEngine On

  3.     RewriteBase /

  4.     RewriteCond %{REQUEST_FILENAME} !-f

  5.     RewriteCond %{REQUEST_FILENAME} !-d

  6.     RewriteRule ^(.*)$ index.php [L,E=PATH_INFO:$1]

  7. </IfModule>
复制代码
2.后台配置typecho伪静态
如图,在typecho后台,开启伪静态,并选择你喜好的url形式:
QQ截图20220724144831.png
具体操作,根据本人实际操作如下
我的虚拟主机是apache的,在网站根目录找到.htaccess,有的没有可能是设置了隐藏文件,显示隐藏文件就能看到了。
然后编辑.htaccess文件,加入上文中对应的apache配置代码保存。然后去typecho程序后台,设置>永久链接,按照上文中图片的设置,保存即可。

e28f3ccaeb1312c.jpg

全部评论 0

Typecho后台设置永久链接后,会在域名后加上index.php,很多人都接受不了。例如如下网址:https://www.域名.com/index.php/archives/37/,但我们希望最终的形式是这样:https://www.域名.com/archives/2514.html。那么我们如何做到这样的效果?
1.配置服务器的rewrite规则
如果在保存上述配置的时候,typecho无法自动配置,那么你可能需要手动配置服务器的rewrite规则。
Linux Apache 环境 (.htaccess):
  1. <IfModule mod_rewrite.c>
  2. RewriteEngine On
  3. # 下面是在根目录,文件夹要修改路径
  4. RewriteBase /
  5. RewriteCond %{REQUEST_FILENAME} !-f
  6. RewriteCond %{REQUEST_FILENAME} !-d
  7. RewriteRule ^(.*)$ /index.php/$1 [L]
  8. </IfModule>
复制代码

Linux Apache 环境(Nginx):
  1. location / {
  2. index index.html index.php;
  3. if (-f $request_filename/index.html) {
  4. rewrite (.*) $1/index.html break;
  5. }
  6. if (-f $request_filename/index.php) {
  7. rewrite (.*) $1/index.php;
  8. }
  9. if (!-f $request_filename) {
  10. rewrite (.*) /index.php;
  11. }
  12. }
复制代码
Windows IIS 伪静态 (httpd.ini):
  1. [ISAPI_Rewrite]
  2. # 3600 = 1 hour
  3. CacheClockRate 3600
  4. RepeatLimit 32
  5. # 中文tag解决
  6. RewriteRule /tag/(.*) /index\.php\?tag=$1
  7. # sitemapxml
  8. RewriteRule /sitemap.xml /sitemap.xml [L]
  9. RewriteRule /favicon.ico /favicon.ico [L]
  10. # 内容页
  11. RewriteRule /(.*).html /index.php/$1.html [L]
  12. # 评论
  13. RewriteRule /(.*)/comment /index.php/$1/comment [L]
  14. # 分类页
  15. RewriteRule /category/(.*) /index.php/category/$1 [L]
  16. # 分页
  17. RewriteRule /page/(.*) /index.php/page/$1 [L]
  18. # 搜索页
  19. RewriteRule /search/(.*) /index.php/search/$1 [L]
  20. # feed
  21. RewriteRule /feed/(.*) /index.php/feed/$1 [L]
  22. # 日期归档
  23. RewriteRule /2(.*) /index.php/2$1 [L]
  24. # 上传图片等
  25. RewriteRule /action(.*) /index.php/action$1 [L]
复制代码
nginx 配置
  1. server {
  2.         listen          80;
  3.         server_name     yourdomain.com;
  4.         root            /home/yourdomain/www/;
  5.         index           index.html index.htm index.php;

  6.         if (!-e $request_filename) {
  7.             rewrite ^(.*)$ /index.php$1 last;
  8.         }

  9.         location ~ .*\.php(\/.*)*$ {
  10.             include fastcgi.conf;
  11.             fastcgi_pass  127.0.0.1:9000;
  12.         }

  13.         access_log logs/yourdomain.log combined;
  14.     }
复制代码

apache 配置
  1. <IfModule mod_rewrite.c>
  2.     RewriteEngine On

  3.     RewriteBase /

  4.     RewriteCond %{REQUEST_FILENAME} !-f

  5.     RewriteCond %{REQUEST_FILENAME} !-d

  6.     RewriteRule ^(.*)$ index.php [L,E=PATH_INFO:$1]

  7. </IfModule>
复制代码
2.后台配置typecho伪静态
如图,在typecho后台,开启伪静态,并选择你喜好的url形式:
QQ截图20220724144831.png
具体操作,根据本人实际操作如下
我的虚拟主机是apache的,在网站根目录找到.htaccess,有的没有可能是设置了隐藏文件,显示隐藏文件就能看到了。
然后编辑.htaccess文件,加入上文中对应的apache配置代码保存。然后去typecho程序后台,设置>永久链接,按照上文中图片的设置,保存即可。

e28f3ccaeb1312c.jpg
热门推荐
您需要登录后才可以回帖 立即登录
说说你的想法......
0
0
0
返回顶部