• I am currently developing a WordPress website. It’s a project that was passed to me from an ex-employee. So forgive my lack of WordPress knowledge as I’m new to this and learning as I go along.

    I have a 2 custom pages which is in the root WordPress folder but is not part of any WordPress templates or file structure. The files are a simple list of some dynamic url links which go to the relevant WordPress custom pages on the site. I want to change the final url which directs to my WordPress page.So I would like

    mydomain.co.uk/page-name/value1/walue2.html to redirect to
    mydomain.co.uk/value1/value2.html

    Ideally I want to use .htaccess to achieve this. How can this be done? Also, where within the WordPress section of the .htaccess file should any rewriting be placed? I’ve found a selection of positions so a bit confused.

    This is a breakdown of the structure of what I’m trying to achieve.

    custom file1 => custom file2 -> WordPress custom page

    Any help would be greatly appreciated.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator Jan Dembowski

    (@jdembowski)

    Forum Moderator and Brute Squad

    Side note: Moved to Fixing WordPress, this is not a Developing with WordPress topic. Please do not use Developing with WordPress for these support topics.

    Thread Starter freakystreakefc

    (@freakystreakefc)

    Sorry, note taken and understood

    Thread Starter freakystreakefc

    (@freakystreakefc)

    I’ve tried various suggestions off other forums and I can actually remove the page name from the URL but it takes me to a ‘page not found’ screen. By placing the ‘page-name’ back in the url then the final page is displayed.

    I will explain my problem a little more.

    I have a dynamic php page which I am linking to my custom WordPress (page name is ‘deltown’) page. Within this url I am passing two variables so that my ‘deltown’ page can get values from a table in the database.

    Currently my url from the .php page to my wordpress ‘deltown’ page is:
    example.com/deltown/value1/value2.html

    In my template functions.php page I have added this set of functions to redirect to the ‘deltown’ page from my php page:

    function custom_rewrite_tag() {
    	add_rewrite_tag('%cid%', '([^&]+)');
    	add_rewrite_tag('%town%', '([^&]+)');
    }
    add_action('init', 'custom_rewrite_tag', 10, 0);
    				
    function custom_rewrite_rule() {
    	add_rewrite_rule('^deltown/([^/]*)/([^/]*)/?','index.php?page_id=3090&cid=$matches[1]&town=$matches[2]','top');
    }
    add_action('init', 'custom_rewrite_rule', 10, 0);

    My permalink for the custom page is:
    example.com/deltown
    and I have no page title set.

    In my .htaccess file I have this:

    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteRule ^deltown/(.*) /$1.html [R=301,L]
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    
    # END WordPress

    I have tried this line RewriteRule ^deltown/(.*) /$1.html [R=302,L] both inside my WordPress block and at the top of the file, outside the Worpress block. This works and produces a url of example.com/value1/value2.html but takes me to a ‘page not found’ page. How can I get the rewritten url to my custom page without ‘deltown’ in the url? Can this even be done?

    The reason why I need the url this way is because we are moving our website from Prestashop over to WordPress/Woocommcerce and we have a few thousand indexed pages in google and don’t want to loose them. If I can get this url to write as I need then the move across platform should be a lot easier

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Rewriting Custom page with .htaccess’ is closed to new replies.