使用 WordPress 隐藏文件夹以显示根目录 使用 htaccess 提供漂亮的永久链接

发布于 2024-10-15 17:45:38 字数 719 浏览 2 评论 0原文

我将 WordPress 安装在子目录中,例如 www.example.com/wordpress。我希望用户点击 www.example.com 并查看 www.example.com/wordpress 的索引。我已经在使用自定义的漂亮永久链接结构 /%category%/%pagename%/ 所以 htaccess 文件对我来说有点陌生。

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

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

# END WordPress

AddType x-mapp-php5 .php
AddHandler x-mapp-php5 .php

我已经通过浏览网络尝试了多种解决方案,但似乎没有任何效果。即使在删除缓存之后,我要么收到内部 500 错误,要么查看根目录中的先前页面,例如 example.com/about(即使我已经删除了根目录中的原始 about.html)。

您提供的任何帮助都将非常有帮助。感谢您抽出时间, 抢

I installed wordpress in a subdirectory, lets say www.example.com/wordpress. I want the user to hit www.example.com and see the index of www.example.com/wordpress. I'm already using a custom pretty permalinks structure /%category%/%pagename%/ so the htaccess file is a little foreign to me.

My current htaccess file looks like this:

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

# END WordPress

AddType x-mapp-php5 .php
AddHandler x-mapp-php5 .php

I've tried numerous solutions from browsing across the web but nothing seems to work. I either get internal 500 errors or view previous pages in the root directory like example.com/about (even though I've deleted the original about.html in the root) even after I deleted my cache.

Any help you could give would be extremely helpful. Thanks for your time,
Rob

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

凉墨 2024-10-22 17:45:38

.htaccess 文件需要位于 / 而不是 /wordpress/ 中,并且 RewriteBase 应该位于 / 而不是 /wordpress/ 中。保留永久链接设置,但不要在 /wordpress/ 中使用 .htaccess 文件。您需要将 WordPress 安装中的根目录设置为 / 并设置 /wordpress/wp-content/ 和 /.htaccess 中其他 WordPress 子目录的重定向,以便对这些目录的请求也能正确转发。

我假设您希望以这种方式设置 WordPress,因为还有其他与 WordPress 安装无关的目录,您希望可以从 / 访问这些目录(例如 www.example.com/cgi-bin/)。您需要在 / 中设置 .htaccess 文件,以使任何目录别名(如 /cgi-bin/)可访问,这样对 /cgi-bin/ 的请求就不会被重定向到 WordPress。

编辑:
我已经很长时间没有做过这样的事情了,但这是我最好的猜测:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule  ^wp-content/(.*)$  /wordpress/wp-content/$1  [L,QSA]
    RewriteRule  ^wp-admin/(.*)$  /wordpress/wp-admin/$1  [L,QSA]
    RewriteRule  ^wp-include/(.*)$  /wordpress/wp-include/$1  [L,QSA]
    RewriteCond %{REQUEST_URI} !^/yourAliasUnrelatedToWordpress [NC,OR]
    RewriteCond %{REQUEST_FILENAME} !-f [OR]
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /wordpress/index.php [L,QSA]
</IfModule>

The .htaccess file needs to be located in / and not in /wordpress/ and RewriteBase should be / not /wordpress/. Leave the permalinks setup on, but don't use an .htaccess file in /wordpress/. You'll need to set the root directory in your wordpress install to / and setup redirects for /wordpress/wp-content/ and the other wordpress subdirs in /.htaccess so that requests to those directories are also forwarded correctly.

I assume that you want to set up wordpress this way because there are other directories not associated with the wordpress install that you want to be accessible from / (www.example.com/cgi-bin/ for example). You'll need to set up your .htaccess file in / to make any directory aliases (like /cgi-bin/) accessible so requests to /cgi-bin/ don't get redirected to wordpress.

EDIT:
I haven't done something like this in a long time, but here's my best guess:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule  ^wp-content/(.*)$  /wordpress/wp-content/$1  [L,QSA]
    RewriteRule  ^wp-admin/(.*)$  /wordpress/wp-admin/$1  [L,QSA]
    RewriteRule  ^wp-include/(.*)$  /wordpress/wp-include/$1  [L,QSA]
    RewriteCond %{REQUEST_URI} !^/yourAliasUnrelatedToWordpress [NC,OR]
    RewriteCond %{REQUEST_FILENAME} !-f [OR]
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /wordpress/index.php [L,QSA]
</IfModule>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文