• Hi, I’m trying to find a way to rewrite the url for a specific category.

    the general permalink structure is :
    mywebiste.tld/myblog/%category%/%postname%-%post_id%/

    I want to skip “/myblog/” if the category name is “OutOfBlog” so that it becomes
    mywebiste.tld/subcategoryname/(+postname)
    instead of
    mywebiste.tld/myblog/OutOfBlog/subcategoryname/(+postname)

    Q1 : is this possible ?
    Q2: I’m trying this with .htaccess in the root directory of WordPress (which is a subdirectory called “myblg” of my website). Is this the right way? I believe using htaccess is faster than using php functions.
    Q3 : I’ve tried things like :
    #RewriteRule ^https://www.mywebiste.com/(.*)$ /OutOfBlog/$1 [L]
    Maybe I should be using the “plain” url instead of an already rewritten url in the condition part, I’m a newbie in all these. Could someone give me a hint ?

    Further Explanation :
    I have a WordPress installed inside my website which runs with prestashop.
    The WordPress is currently used just for my blog but I want to use it for some articles on my site, for it seems much easier with WordPress, but I don’t want “myblog” to appear on the url.

    Even a partial reply would be appreciated.
    Thanks in advance for your help.

Viewing 4 replies - 1 through 4 (of 4 total)
  • In the WordPress dashboard go to settings>permalinks
    There you will see the options for editing the permalinks.

    If the “myblog” portion of the URL is uneditable, then it is the name of the folder in which WordPress is installed.

    Renaming the folder to something you find more acceptable could solve your problem. Do not simply change the name of the folder! Doing so will break large portions of your site.

    If you rename the folder to “WordPress”,
    Then the urls will change from:
    mywebiste.tld/myblog/OutOfBlog/subcategoryname/(+postname
    to:
    mywebiste.tld/WordPress/OutOfBlog/subcategoryname/(+postname)

    The directions for moving your blog to another folder can be found here: Moving WordPress

    Thread Starter Alelouya

    (@alelouya)

    Thank you very much for your reply, wheynne.
    Indeed, “myblog” is the real physical folder name in which the WordPress is installed.
    The thing is that I don’t want to change this at all, I only want to hide this folder name for one category I made in purpose of using WordPress for somethig else than a blog.

    There are already topics in this forum about changing the permalink for one specific category, but the suggested solutions use php – Rewrite API, but I assumed it would be quicker to do this in .htaccess ; besides, in the .htacess, there’s an instrucion of basename with “myblog” (It seems to me it’s unnecessary because it’s the same as the folder name ) and I suppose I should neutralize this.

    Anyway, it seems to me that what I need is .htacess instructions like :
    RewriteCond %{REQUEST_URI} “the already rewritten url contains OutOfBlog”
    or “?id_category=x (?, I don’t know the url structure for one cateogry archive page)”
    RewriteRule “Rewrite the url to mywebiste.tld/subcategoryname/(+postname) by skipping the basename ‘myblog'”.

    But maybe I might as well do this with Rewrite API…
    Or I should be doing this with the .htaccess in the root folder – parent folder of “myblog”…

    I misunderstood your original need in the first post.

    The difference between writing directly to .htaccess and utilizing the php rewrite api depends on the scale of your site, and how many redirects you wish to create.

    If you are only moving over one category, I would suggest using the method you feel most comfortable with. You seem to have done a bit of research already. Remember to make back ups, and read up-to-date documentation.

    Finally, the category queries are:

    ?cat=4,5,6
    ?category_name=CMS
    ?tag=wordpress
    Thread Starter Alelouya

    (@alelouya)

    Thanks for your reply.
    So far, using .htaccess of the root folder, I managed to rewrite the url without WP folder name
    RewriteRule ^subcategoryname/(.*)$ myblog/OutOfBlog/subcategoryname/$1 [L]
    but it ends up with a url with WP folder name (site url of my WP blog).
    I placed the same instruction in the .htaccess of WP folder, using L flag and before the other instructions, but it changes nothing.
    So I suppose I should edit the part (if there is no need to work on php/Rewrite API) :

    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /myblog/
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /myblog/index.php [L]
    </IfModule>

    How can I do this ??
    First, should I remove RewriteBase /myblog/ ? Anyway, it’s the name of the physical folderwhere WP is insalled, but I’m a bit afraid to do this.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘url rewriting of a specific category’ is closed to new replies.