skip to Main Content

I want to change URLs in one folder (cartoon) in my site to friendly SEO URLs.
This folder (cartoon) includes a PHP script not related to WordPress.

From:

example.com/cartoon/index.php?v=TitleEpisode

To:

example.com/cartoon/TitleEpisode

I read here all related questions but I did not benefit.

I have WordPress on my main domain (example.com).

I found this code in .htaccess file:

DirectoryIndex index.html index.php index.htm parking-page.html

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

# END WordPress

What do I do?

3

Answers


  1. Chosen as BEST ANSWER

    it's done. i enter this after the first line in .htaccess

    # BEGIN for Cartoon Folder
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^/?cartoon/(.+)$ /cartoon/?v=$1 [L,QSA]
    
    # END for Cartoon Folder
    

    thank u very much


  2. Ok, based on the edit, it seems like what you want is for WordPress not to rewrite that slug but to ignore it.

    You can do this by editing your .htaccess to exclude a folder. Make sure the folder is in the root directory of your site, as in, the same folder as wp-admin, wp-content, and wp-includes.

    Then, open your .htaccess and add a rewrite rule to ignore that folder:

    DirectoryIndex index.html index.php index.htm parking-page.html
    
    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index.php$ - [L]
    
    # Add this condition with the folder you want to ignore (cartoon in your example)
    RewriteCond %{REQUEST_URI} !^/(cartoon|cartoon/.*)$
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    
    # END WordPress
    

    OLD ANSWER

    Well, this is fairly open-ended. For a better answer, please edit the question to include what you have already tried. Also, what do you mean by “one folder”? Is this a custom post type? Is it a category or custom taxonomy? Are there different permalinks for different types/taxonomies? Please provide more details on what you want to do.

    But for the usual case, here is the documentation for pretty permalinks.

    First, make sure URL Rewriting is enabled in Apache. Example in Ubuntu/Debian

    sudo a2enmod rewrite
    sudo service apache2 restart
    

    Now, in wp-admin, go to Settings -> Permalinks. Set the permalink to Post Name.

    enter image description here

    Then click save changes. It will either save the new .htaccess automatically if your site has the permissions to, or it will give you the new content of .htaccess to copy and paste.

    Now you should be able to view a post or page and it should show the SEO-friendly links.

    Login or Signup to reply.
  3. How are you implementing (or intending to implement) the routing of example.com/cartoon/TitleEpisode?

    If this is entirely outside of WordPress then I would expect you to have an additional .htaccess file inside the /cartoon subdirectory (since this is presumably a physical subdirectory)? This alone should be sufficient to override the WordPress mod_rewrite directives in the parent .htaccess file, since mod_rewrite directives are not inherited by default.

    For instance, simply enabling the RewriteEngine in a subdirectory is sufficient to override the WP directives.

    In /cartoon/.htaccess:

    RewriteEngine On
    

    Then, in order to route a URL of the form /cartoon/TitleEpisode to /cartoon/index.php?v=TitleEpisode, you would need something like:

    RewriteRule ^index.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ([^/]+) index.php?v=$1 [L]
    

    (A bit similar to the WP directives in the parent .htaccess file.)


    I would avoid editing between the # BEGIN and # END WordPress markers in the parent .htaccess file since these could be overridden by future WP updates.

    You would instead implement an exception before the WP directives. For example:

    RewriteRule ^cartoon - [L]
    

    However, as mentioned above, you are probably better off creating an additional .htaccess file in the subdirectory and avoid touching the WordPress installation at all.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search