问题
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