重写URL后找不到对象错误 [英] Object not found error after rewrite the URL

查看:87
本文介绍了重写URL后找不到对象错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的网站上有两种URL

I have two types of URL on my website which are

第一个URL集

<a href="services_name1">Service name1</a>

第二个URL集

<a href="journel.php?name=services_name1">Service name1</a>

现在我正在做的是,对于第一个URL,我想要类似这样的URL

Now what I am doing is, For the first URL, I want URL like

services/services_name1

因此我在htaccess中使用了以下代码,并且可以正常运行

So I used like below code in htaccess and it's working

RewriteRule ^services/services_name1$ services_name1

我的问题是第二个URL。
对于第二个URL,我想要我的URL

My issue is with the second URL. For the second URL, I want my URL like

services/authors/services_name1

我在htaccess中尝试了以下代码

I tried below code in htaccess

RewriteRule ^/?services/authors/([0-9]+)$ /journel.php?name=$1

,但不起作用。我得到404。

but it not working. I am getting 404.

我正在使用< a href = services / authors / services_name1>点击此处< / a>

.htaccess

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
RewriteCond %{HTTPS} off
RewriteRule ^home$ index
RewriteRule ^about-us$ aboutus
RewriteRule ^services/authors$ authors


RewriteRule ^/?services/authors/([0-9\w]+)$ /journel.php?name=$1

FileETag MTime Size
</IfModule>

您能帮我解决这个问题吗?

Would you help me out with this issue?

推荐答案

规则:

RewriteRule ^/?services/authors/([0-9]+)$ /journel.php?name=$1

仅匹配数字(因为 / authors / 之后的 0-9 ),例如 / authors / 22 / 。要允许使用字符(单词/破折号) \w

only matches numbers(because of the 0-9) after /authors/ such as /authors/22/. To allow characters(words/dashes) \w can be used:

RewriteRule ^/?services/authors/([0-9\w]+)$ /journel.php?name=$1

具有整个.htaccess的更新的订单:

Updated order with entire .htaccess:

# BEGIN WordPress
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
RewriteCond %{HTTPS} off
RewriteRule ^home$ index
RewriteRule ^about-us$ aboutus
RewriteRule ^services/authors$ authors
RewriteRule ^/?services/authors/([0-9\w]+)$ /journel.php?name=$1

FileETag MTime Size
</IfModule>

签出正则表达式速查表: https://www.rexegg.com/regex-quickstart.html

Checkout the regex cheatsheet: https://www.rexegg.com/regex-quickstart.html

这篇关于重写URL后找不到对象错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆