permalinks - Removehide a specify category-name from the url

admin2025-01-08  3

I have several categories post:

General
News
Comedy
Competitions
Culture
Gaming
Food
etc

The posts url are in the following format:

www.mydomain/category-name/post-title

Example:

www.mydomain/food/how-to-make-paella
www.mydomain/gaming/game-of-theday

But I would like to hide from the URL the category name 'general' so for example.

instead of

www.mydomain/general/how-to-learn-spanish

have

www.mydomain/how-to-learn-spanish

I have tried some wiring a rewrite rule in the .htaccess but doesn't work.

Any idea how can I do it?

Thanks!

I have several categories post:

General
News
Comedy
Competitions
Culture
Gaming
Food
etc

The posts url are in the following format:

www.mydomain.com/category-name/post-title

Example:

www.mydomain.com/food/how-to-make-paella
www.mydomain.com/gaming/game-of-theday

But I would like to hide from the URL the category name 'general' so for example.

instead of

www.mydomain.com/general/how-to-learn-spanish

have

www.mydomain.com/how-to-learn-spanish

I have tried some wiring a rewrite rule in the .htaccess but doesn't work.

Any idea how can I do it?

Thanks!

Share Improve this question asked Sep 8, 2016 at 11:26 andresglandresgl 1641 gold badge3 silver badges14 bronze badges
Add a comment  | 

3 Answers 3

Reset to default 0

You can use post name in your permalinks setting. And for Category Base and Tag Base make it blank

Hope this will help

Have you tried following Rewrite rule in your .htaccess ?

RewriteRule ^category/(.+)$ http://YOUR_SITE_NAME/$1 [R=301,L]

To achieve the desired URL structure where the category name is hidden for the "General" category, you can use the following .htaccess rules

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    
    # Exclude the 'general' category from the URL
    RewriteCond %{REQUEST_URI} !^/general/
    
    # Rewrite the URL for posts in other categories
    RewriteRule ^([^/]+)/([^/]+)$ /$1/$2 [L]
    
    # Rewrite the URL for posts in the 'general' category
    RewriteRule ^([^/]+)$ /general/$1 [L]
</IfModule>
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1736270001a1395.html

最新回复(0)