删除 URL 重写不起作用的子文件夹

Remove subfolder with URL Rewriting not working

我正在尝试重写 URL 包含的内容,如下所示: https://mywebsite/FOF/news/page/page1.php

我认为它不像 url 那样美观,我希望它看起来更像这样:

https://mywebsite/customPage

此请求非常具体 url https://mywebsite/FOF/news/page/page1.php

我的代码有效,重写了 https://mywebsite/FOF 目录的 url,但另一方面,我网站的主要 url 和 urls 的其他文件不再访问,我不明白我的错误来自哪里,如果有人可以帮助我

Options +FollowSymlinks
RewriteBase /    
RewriteEngine on    
RewriteRule ^page1$ page1.php    
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+FOF/news/page/([^\s]+) [NC]    
RewriteRule ^%1 [R=301,L]   
RewriteCond %{REQUEST_FILENAME} !-f   
RewriteRule (?!^FOF/news/page/)^(.*)$ /FOF/news/page/ [L?NC]

对于您显示的示例,能否请您尝试遵循 htacces 文件中的规则。确保你的 htaccess 文件与 FOF 文件夹放在一起(不在里面)。

请确保在测试您的 URL 之前清除您的浏览器缓存。

##Enabling FollowSymlinks and disabling MultiViews options here.
Options +FollowSymlinks -MultiViews
##Setting rewrite base to / here.
RewriteBase /
RewriteEngine on
##Rewriting for page1 uri here.
RewriteRule ^page1$ page1.php    
##External redirect rules here.
RewriteCond %{THE_REQUEST} \s/FOF/news/page/page1\.php\s [NC]
RewriteRule ^ /customPage? [R=301,L]

##Internal rewrite rules here...
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^customPage/?$ FOF/news/page/page1.php [L,NC]