开发者

Directory Overriding on Wordpress

开发者 https://www.devze.com 2023-02-05 15:35 出处:网络
In WordPress, I have a page called开发者_StackOverflow社区 Experiments with a slug of experiments. That page should be able to be accessed at http://site.com/experiments.

In WordPress, I have a page called开发者_StackOverflow社区 Experiments with a slug of experiments. That page should be able to be accessed at http://site.com/experiments.

Problem is, I also want to have a folder on my server with that name so that http://site.com/experiments/thing/ loads the index.html file of the folder (if there is one).

I thought I had found the perfect rewrite structure (from this blog post):

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

# BEGIN WordPress
# END WordPress

It looks like it rewrites directories using WordPress unless the directory has an index.html or index.php file in which case it loads it ignoring WordPress. And it works perfectly for subdirectories, but http://site.com/experiments/ tries to redirect to http://site.com/experiments back and forth forever.

Anyone know what I'm doing wrong?


Figured it out. Wordpress wasn't adding trailing slashes to items, so it was sending me to /experiments and then Apache wanted to send me back to /experiments/ resulting in a loop.

Did a ton of reading on URLs (which was very interesting/fun) and now have decided to add trailing slashes to all my URLs. And everything is working perfectly.

Edit: An interesting side note is that Wordpress decides whether to use trailings slashes everywhere based on whether there is one in your custom permalink structure (ie. /%postname%/). Wasted a good amount of time searching as to where I set that, and it was right there all along.

0

精彩评论

暂无评论...
验证码 换一张
取 消