【发布时间】:2022-01-22 08:13:51
【问题描述】:
我很确定这是重复的,但我只是不知道如何找到这个简单问题的答案。
所以我有这个本地页面 - WP 页面:https://localhost/mrdigital/alias-links-pdf/
下面的代码是模型 - 用于 /alias-links-pdf/ 页面的模板文件。
在模板文件中有两个链接。单击下载时,这两个链接都会生成两个不同的 PDF 文件。 (一个带参数的文件,另一个不带参数的文件)
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
get_header(); ?>
<?php the_title(); ?>
<?php if (have_posts()) : while(have_posts()) : the_post(); ?>
<?php the_content(); ?>
<?php endwhile; endif; ?>
<section>
<div class="page_book_title">
Book Genres - What Kinds of Books Are There?<br>
There are very different types of books - Let's tell you which ones!
</div>
<div class="page_book_pdf">
<ul>
<li><a href="https://localhost/mrdigital/wp-content/themes/astra-child/pdf.php?key=1360">PDF One </a></li>
<li><a href="https://localhost/mrdigital/wp-content/themes/astra-child/pdf.php">PDF Two</a></li>
</ul>
</div>
</section>
<?php get_footer(); ?>
我需要为两个链接或两个 URL 创建一个别名,因为当鼠标悬停时,它会显示整个文件目录。该文件夹已暴露,这是不希望的。
我需要使用这样的东西,所以当用户悬停指针时,我们会看到一个别名。
这也是一个 url 路由。https://localhost/mrdigital/items/
然后我尝试在 .htaccess 中使用以下行,但代码有问题。页面进入循环。
# BEGIN Code
RewriteRule ^mrdigital/pdf-one$ wp-content/themes/astra-child/pdf.php?key=1360 [L]
RewriteRule ^mrdigital/pdf-two$ wp-content/themes/astra-child/pdf.php [QSD,L]
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /mrdigital/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /mrdigital/index.php [L]
RewriteRule ^(.*)$ /mrdigital/wp-content/themes/astra-child/page-aliasurl.php?url=$1 [QSA,L]
</IfModule>
这个别名的最简单方法应该是什么?
甚至可以对同一个 .htaccess 文件中的两个不同文件进行重写吗?
感谢任何帮助。
【问题讨论】:
-
您的
.htaccess文件在哪里?是在文档根目录下,还是在/mrdigital子目录下? -
您好@MrWhite,非常感谢您的帮助!我会做修改,我给你一个反馈。这是文件路径。 C:\xampppserver\htdocs\mrdigital\.htaccess
-
我再次编辑了问题中的代码块(.htaccess 块),所以你可以看到我是如何使用它的。
标签: php apache .htaccess redirect alias