WordPress.org

Ready to get started?Download WordPress

Forums

.htaccess help - adding a custom directory to www/home directory, override WP (4 posts)

  1. alexanderacook
    Member
    Posted 5 years ago #

    Here's my situation:

    1. I want to have a custom page on my wordpress instillation at /checkout.

    2. I added a "checkout" folder in my domain.

    3. I added index.php in the checkout folder.

    4. I want to be able to go to /checkout/step1, /checkout/step2..

    5. WordPress sees that page as "not existing", even though it's technically not a WordPress post/category - it's a subfolder in the Home/www directory.

    Does anyone know how to tell WordPress to ignore the fact that /checkout/XXX does not exist?

    I'm sure it's a .htaccess issue, but can someone lend me hand?

    My first step was to copy my existing .htacess file to /checkout. Here is what is currently in /checkout/.htaccess:
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>

    Thanks for the help in advance

  2. codestyling
    Member
    Posted 5 years ago #

    The main .htaccess in WP root folder could look like this:

    # BEGIN Alexander
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^checkout/step1$ /checkout/step1.php [QSA,L]
    RewriteRule ^checkout/step2$ /checkout/step2.php [QSA,L]
    RewriteRule ^checkout/step3$ /checkout/step3.php [QSA,L]
    </IfModule>
    # END Alexander
    
    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    # END WordPress

    Your own block ensures, that the urls with checkout/step1 will be translated and directed to checkout/step1.php and delivered.
    Keep in mind, that you will normally not be able to access at this php paged workpress code as long as you not launch the loader from wp.

    You could also direct all steps to one php file by giving as param like this, but please sanitize the incomming param value carefully:

    # BEGIN Alexander
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^checkout/(.*)$ /checkout.php?step=$1 [QSA,L]
    </IfModule>
    # END Alexander
    
    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    # END WordPress

    where you now get at the checkout.php as $_GET['step'] the given step(s) like "step1" but there could also arrive some bad things, check it!

  3. alexanderacook
    Member
    Posted 5 years ago #

    Wow! Thanks for the super detailed feedback.

    I'll give it a try now.

    Thanks!!!

  4. alexanderacook
    Member
    Posted 5 years ago #

    Thanks - that worked!

    I have a similarly related question -

    Let's say I have a wordpress page, e.g. mysite.com/storefinder.

    I'd like to be able to have urls like /storefinder/united-states/state/city/etc/etc.

    How do I overwrite the WordPress 404 errors for this situation? I have a page setup called storefinder, and in that page I have some PHP code - but if I go to /storefinder/anything - WordPress throws a 404 error.

    Any ideas?

    Thanks again @codestyling for answering my first question.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags