Object not found error after rewrite the URL [duplicate]

允我心安 提交于 2019-12-11 17:00:16

问题


I have two types of URL on my website which are

First URL set

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

Second URL set

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

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

services/services_name1

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

RewriteRule ^services/services_name1$ services_name1

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

services/authors/services_name1

I tried below code in htaccess

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

but it not working. I am getting 404.

I am using <a href="services/authors/services_name1">click here</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?


回答1:


the rule:

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

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

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>

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



来源:https://stackoverflow.com/questions/57736704/object-not-found-error-after-rewrite-the-url

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!