使用“last”在 .htaccess 中排除 URL 重写旗帜

发布于 2024-08-28 12:15:34 字数 1966 浏览 2 评论 0原文

WordPress 已作为博客安装到 osCommerce 中。我正在尝试让 WordPress RSS 源正常工作。所有 WP 核心文件都存在,但我在访问 mydomain.com/wordpress/feed/ 上的提要时遇到各种错误,例如 404、“提要无法更新,因为源文件不再可用”,甚至是原始错误osCommerce feed 文件中的 php 代码在浏览器中。

我认为问题出在 osCommerce 的重写规则上,我想如果我可以将 WP feed URL 排除在重写之外,它将修复 feed 或帮助找到真正的问题。

环顾四周,我找到了一个解决方案,可以在 URL 上使用“last”标志来防止它被重写。问题是,现有的 .htaccess 已经有一个带有“last”标志的规则。

有没有办法不重写 WP feed URL?可以添加另一个“最后”规则吗?在搞乱 .htaccess 之前,我想尝试一些明确的事情,以避免破坏网站。

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ http://www.mydomain.com/index.php?cPath=$1 [L]

RewriteRule ^(.*)-p-([0-9]+).html$ product_info.php?products_id=$2&%{QUERY_STRING}
RewriteRule ^(.*)-c-([0-9]+).html$ index.php?cPath=$2&%{QUERY_STRING}
RewriteRule ^(.*)-m-([0-9]+).html$ index.php?manufacturers_id=$2&%{QUERY_STRING}
RewriteRule ^(.*)-pi-([0-9]+).html$ popup_image.php?pID=$2&%{QUERY_STRING}
RewriteRule ^(.*)-pr-([0-9]+).html$ product_reviews.php?products_id=$2&%{QUERY_STRING}
RewriteRule ^(.*)-pri-([0-9]+).html$ product_reviews_info.php?products_id=$2&%{QUERY_STRING}

RewriteRule ^(.*)-t-([0-9_]+).html$ articles.php?tPath=$2&%{QUERY_STRING}
RewriteRule ^(.*)-au-([0-9]+).html$ articles.php?authors_id=$2&%{QUERY_STRING}
RewriteRule ^(.*)-a-([0-9]+).html$ article_info.php?articles_id=$2&%{QUERY_STRING}
# Information pages
RewriteRule ^(.*)-i-([0-9]+).html$ information.php?info_id=$2&%{QUERY_STRING}

RewriteRule ^(.*)-links-([0-9_]+).html$ links.php?lPath=$2&%{QUERY_STRING}

RewriteRule ^(.*)-n-([0-9]+).html$ newsdesk_info.php?newsdesk_id=$2&%{QUERY_STRING}
RewriteRule ^(.*)-nc-([0-9]+).html$ newsdesk_index.php?newsPath=$2&%{QUERY_STRING}
RewriteRule ^(.*)-nri-([0-9]+).html$ newsdesk_reviews_info.php?newsdesk_id=$2&%{QUERY_STRING}
RewriteRule ^(.*)-nra-([0-9]+).html$ newsdesk_reviews_article.php?newsdesk_id=$2&%{QUERY_STRING}

WordPress has been installed as a blog into osCommerce. I'm trying to get the WordPress RSS feed to work. All WP core files exist, but I get all kinds of errors accessing the feed at mydomain.com/wordpress/feed/, like 404s, "the feed can't be updated because the source file is no longer available," or even raw php code in the browser from the osCommerce feed file.

I think the problem is the rewrite rules for osCommerce, and I'm thinking if I can exclude the WP feed URL from rewrite, it will fix the feed or help find the real issue.

Looking around SO, I found a solution to use the "last" flag on a URL to prevent it from being rewritten. Problem is, the existing .htaccess already has a rule with a "last" flag on it.

Is there a way to not rewrite the WP feed URL? Can another "last" rule be added? I'd like to have some definite things to try before messing with .htaccess to avoid disrupting the site.

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ http://www.mydomain.com/index.php?cPath=$1 [L]

RewriteRule ^(.*)-p-([0-9]+).html$ product_info.php?products_id=$2&%{QUERY_STRING}
RewriteRule ^(.*)-c-([0-9]+).html$ index.php?cPath=$2&%{QUERY_STRING}
RewriteRule ^(.*)-m-([0-9]+).html$ index.php?manufacturers_id=$2&%{QUERY_STRING}
RewriteRule ^(.*)-pi-([0-9]+).html$ popup_image.php?pID=$2&%{QUERY_STRING}
RewriteRule ^(.*)-pr-([0-9]+).html$ product_reviews.php?products_id=$2&%{QUERY_STRING}
RewriteRule ^(.*)-pri-([0-9]+).html$ product_reviews_info.php?products_id=$2&%{QUERY_STRING}

RewriteRule ^(.*)-t-([0-9_]+).html$ articles.php?tPath=$2&%{QUERY_STRING}
RewriteRule ^(.*)-au-([0-9]+).html$ articles.php?authors_id=$2&%{QUERY_STRING}
RewriteRule ^(.*)-a-([0-9]+).html$ article_info.php?articles_id=$2&%{QUERY_STRING}
# Information pages
RewriteRule ^(.*)-i-([0-9]+).html$ information.php?info_id=$2&%{QUERY_STRING}

RewriteRule ^(.*)-links-([0-9_]+).html$ links.php?lPath=$2&%{QUERY_STRING}

RewriteRule ^(.*)-n-([0-9]+).html$ newsdesk_info.php?newsdesk_id=$2&%{QUERY_STRING}
RewriteRule ^(.*)-nc-([0-9]+).html$ newsdesk_index.php?newsPath=$2&%{QUERY_STRING}
RewriteRule ^(.*)-nri-([0-9]+).html$ newsdesk_reviews_info.php?newsdesk_id=$2&%{QUERY_STRING}
RewriteRule ^(.*)-nra-([0-9]+).html$ newsdesk_reviews_article.php?newsdesk_id=$2&%{QUERY_STRING}

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

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

发布评论

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

评论(1

ぃ双果 2024-09-04 12:15:34

我建议使用两个 .htaccess 文件:一个位于 WordPress 目录中,用于捕获应由 WordPress 处理的所有请求,另一个位于根目录中,用于捕获其余请求。

我不太确定您的重写规则中的 %{QUERY_STRING} ...彻底测试一下。另外,我没有任何使用 Magento 的经验。上次我测试的时候,速度太慢了。 :)

首先,这里有两个 .htaccess 文件:

/wordpress/.htaccess

RewriteEngine On
RewriteBase /wordpress/

# WordPress allows URLs like /2010/0/ or /00/ == doubled content
RewriteRule (^0+|(.*)/0+)/$ /$2 [L,R=301]

# WordPress: paged content creates a /page/
RewriteRule (^p|(.*)/p)age/(1/)?$ /$2 [L,R=301]

# Images, Stylesheets etc.
RewriteCond %{REQUEST_URI} !.+\.\w{2,4}$
# Existing file
RewriteCond %{REQUEST_FILENAME} !-f
# Existing directory
RewriteCond %{REQUEST_FILENAME} !-d
# Symbolic link
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^ index.php [L]

root /.htaccess

RewriteEngine On
RewriteBase /

RewriteRule ^(.*)-p-([0-9]+).html$ product_info.php?products_id=$2&%{QUERY_STRING} [L]
RewriteRule ^(.*)-c-([0-9]+).html$ index.php?cPath=$2&%{QUERY_STRING} [L]
RewriteRule ^(.*)-m-([0-9]+).html$ index.php?manufacturers_id=$2&%{QUERY_STRING} [L]
RewriteRule ^(.*)-pi-([0-9]+).html$ popup_image.php?pID=$2&%{QUERY_STRING} [L]
RewriteRule ^(.*)-pr-([0-9]+).html$ product_reviews.php?products_id=$2&%{QUERY_STRING} [L]
RewriteRule ^(.*)-pri-([0-9]+).html$ product_reviews_info.php?products_id=$2&%{QUERY_STRING} [L]
RewriteRule ^(.*)-t-([0-9_]+).html$ articles.php?tPath=$2&%{QUERY_STRING} [L]
RewriteRule ^(.*)-au-([0-9]+).html$ articles.php?authors_id=$2&%{QUERY_STRING} [L]
RewriteRule ^(.*)-a-([0-9]+).html$ article_info.php?articles_id=$2&%{QUERY_STRING} [L]
# Information pages
RewriteRule ^(.*)-i-([0-9]+).html$ information.php?info_id=$2&%{QUERY_STRING} [L]

RewriteRule ^(.*)-links-([0-9_]+).html$ links.php?lPath=$2&%{QUERY_STRING} [L]

RewriteRule ^(.*)-n-([0-9]+).html$ newsdesk_info.php?newsdesk_id=$2&%{QUERY_STRING} [L]
RewriteRule ^(.*)-nc-([0-9]+).html$ newsdesk_index.php?newsPath=$2&%{QUERY_STRING} [L]
RewriteRule ^(.*)-nri-([0-9]+).html$ newsdesk_reviews_info.php?newsdesk_id=$2&%{QUERY_STRING} [L]
RewriteRule ^(.*)-nra-([0-9]+).html$ newsdesk_reviews_article.php?newsdesk_id=$2&%{QUERY_STRING} [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule (.*) /index.php?cPath=$1 [L]

您的网络托管商有一个非常丰富的信息 RewriteLog,如果您仍然遇到任何问题,这可能会有所帮助。

I recommend to use two .htaccess files: one in your wordpress directory which catches all requests which should be handled by WordPress and one in your root directory for the rest.

I’m not so sure about the %{QUERY_STRING} in your rewrite rules … test it thoroughly. Also, I don’t have any experience with Magento. The last time I tested it, it was way too slow. :)

As a start, here are the two .htaccess files:

/wordpress/.htaccess

RewriteEngine On
RewriteBase /wordpress/

# WordPress allows URLs like /2010/0/ or /00/ == doubled content
RewriteRule (^0+|(.*)/0+)/$ /$2 [L,R=301]

# WordPress: paged content creates a /page/
RewriteRule (^p|(.*)/p)age/(1/)?$ /$2 [L,R=301]

# Images, Stylesheets etc.
RewriteCond %{REQUEST_URI} !.+\.\w{2,4}$
# Existing file
RewriteCond %{REQUEST_FILENAME} !-f
# Existing directory
RewriteCond %{REQUEST_FILENAME} !-d
# Symbolic link
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^ index.php [L]

root /.htaccess

RewriteEngine On
RewriteBase /

RewriteRule ^(.*)-p-([0-9]+).html$ product_info.php?products_id=$2&%{QUERY_STRING} [L]
RewriteRule ^(.*)-c-([0-9]+).html$ index.php?cPath=$2&%{QUERY_STRING} [L]
RewriteRule ^(.*)-m-([0-9]+).html$ index.php?manufacturers_id=$2&%{QUERY_STRING} [L]
RewriteRule ^(.*)-pi-([0-9]+).html$ popup_image.php?pID=$2&%{QUERY_STRING} [L]
RewriteRule ^(.*)-pr-([0-9]+).html$ product_reviews.php?products_id=$2&%{QUERY_STRING} [L]
RewriteRule ^(.*)-pri-([0-9]+).html$ product_reviews_info.php?products_id=$2&%{QUERY_STRING} [L]
RewriteRule ^(.*)-t-([0-9_]+).html$ articles.php?tPath=$2&%{QUERY_STRING} [L]
RewriteRule ^(.*)-au-([0-9]+).html$ articles.php?authors_id=$2&%{QUERY_STRING} [L]
RewriteRule ^(.*)-a-([0-9]+).html$ article_info.php?articles_id=$2&%{QUERY_STRING} [L]
# Information pages
RewriteRule ^(.*)-i-([0-9]+).html$ information.php?info_id=$2&%{QUERY_STRING} [L]

RewriteRule ^(.*)-links-([0-9_]+).html$ links.php?lPath=$2&%{QUERY_STRING} [L]

RewriteRule ^(.*)-n-([0-9]+).html$ newsdesk_info.php?newsdesk_id=$2&%{QUERY_STRING} [L]
RewriteRule ^(.*)-nc-([0-9]+).html$ newsdesk_index.php?newsPath=$2&%{QUERY_STRING} [L]
RewriteRule ^(.*)-nri-([0-9]+).html$ newsdesk_reviews_info.php?newsdesk_id=$2&%{QUERY_STRING} [L]
RewriteRule ^(.*)-nra-([0-9]+).html$ newsdesk_reviews_article.php?newsdesk_id=$2&%{QUERY_STRING} [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule (.*) /index.php?cPath=$1 [L]

Your web hoster has a very informative RewriteLog, which may help if you still have any problems.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文