首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何修改非WordPress文档的HTACCESS文件

问如何修改非WordPress文档的HTACCESS文件
EN

Stack Overflow用户
提问于 2019-10-06 06:40:44
回答 1查看 230关注 0票数 0

我的网站既有WordPress文件,也有非WordPress文件。对于我的WordPress文件,.htaccess文件工作得很好。例如:https://suncatcherstudio.com/monograms/index.php get重定向到:https://suncatcherstudio.com/monograms/

但是,我的非WordPress文件不会被重定向。例如,https://suncatcherstudio.com/monogram-maker/index.php不会被重定向。我想把"index.php“去掉。实际上,将此文档重定向到:https://suncatcherstudio.com/monogram-maker/

我当前的.htaccess文件如下所示:

代码语言:javascript
复制
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [L,NE,R=301]


# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

一个人建议有两个.htaccess文件。但是,我不希望每次添加重定向时都必须修改两个文件。任何帮助都将不胜感激。谢谢,比尔

EN

回答 1

Stack Overflow用户

发布于 2019-10-07 00:38:04

解决(5小时后!)当第二次调用程序时,我的PHP程序中的以下代码导致"index.php“出现在URL的末尾。

代码语言:javascript
复制
<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>

我只需将此代码替换为:

代码语言:javascript
复制
   <?php echo htmlspecialchars('https://suncatcherstudio.com/monogram-maker/');?>

使用PHP_SELF:

代码语言:javascript
复制
 First time called: https://suncatcherstudio.com/monogram-maker/
Second time called: https://suncatcherstudio.com/monogram-maker/index.php

新方法:

代码语言:javascript
复制
  First time called: https://suncatcherstudio.com/monogram-maker/
 Second time called: https://suncatcherstudio.com/monogram-maker/
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58252878

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档