【发布时间】:2018-04-06 11:27:38
【问题描述】:
我检查了数百个与我的问题相关的主题并尝试了所有这些主题。 到目前为止,我无法得到我正在寻找的结果:
我正在尝试将子文件夹“故事”重定向到另一个“新闻”,但 index.html 和子文件夹本身除外。 整个过程保持沉默(网址仍然显示上一个子文件夹)。
ps:.htaccess 文件所在的是子目录,而不是域的根目录。
意思:
/stories/ --> /stories/
/stories/index.html --> /stories/index.html
/stories/whatever/ --> /news/whatever/ (but still showing /stories/whatever/)
/stories/whatever --> /news/whatever (but still showing /stories/whatever)
到目前为止我已经试过了:
+FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_REFERER} ^http://www.example.com [NC]
RewriteCond %{REQUEST_URI} !^/stories/index.html$
RewriteCond %{REQUEST_URI} !^/stories/$
RewriteRule ^(.*)$ /news/$1/ [P,L]
这适用于:/stories/whatever,但如果我在末尾添加 /:404 错误。 如果我在地址栏中复制 url,/stories/ 和 /stories/index.html 正在工作。但如果我点击一个链接,它会转到 /news/ 并且非静音(显示 /news/ 的网址)
我有点迷茫,尝试了很多不同的方法:
RewriteCond %{REQUEST_FILENAME} !-f
仍然无法正常工作。有什么建议吗?
提前致谢。
【问题讨论】:
标签: apache .htaccess redirect mod-rewrite url-rewriting