• Resolved morollian

    (@morollian)


    Hello!
    I’m having troubles with a website based on WordPress 4.0.

    In my website there is a page wich must have certain name, let’s call it mandatory_name. I can do nothing about it because this name (and consequently the url) are mandatory by law. The problem is that already exisits a directory with the same name.

    THE PROBLEM: When a user types the url https://www.mywebsite/mandatory_name, the browser shows the content of the folder /mandatory_name instead of the content of the page “mandatory_name”.

    Any clue would be very appreciated… I’m so lost here!

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

    (@bcworkz)

    I don’t suppose you could just rename the folder? You’d probably have done that if it were possible.

    Thus you’ll need another mod_rewrite block in your .htaccess file. If you look at the file, WP has inserted a block that sends requests without matching file or folder names to index.php. Add another one for where the request is for mandatory_name or whatever. Include the ‘/?$’ terminator in the regexp so requests for particular files in the folder still work, only requests for the folder with nothing else after it are sent to index.php.

    Thread Starter morollian

    (@morollian)

    Thanks a lot bcworkz

    I tried your solution, and it worked. The only problem is that i needed my site to show a page with the same name as the folder, not to go to the home (index.php).

    I’ve finally found a solution that seems to do the trick.
    I’m using a redirection with the [P] flag, so it’s done “behind the scenes” and does exactly what I needed. I’ve also changed the name of the page (mandatory_name) for an alias. This way my site shows the content I wanted, keeping the url I needed.

    Here’s the code if anyone needs it:

    <IfModule mod_rewrite.c>
    
    RewriteEngine on
    RewriteBase /
    RewriteRule ^mandatory_name/(.*)$ https://www.myweb.com/alias/$1 [P]
    
    </IfModule>

    Thanks for the hint bcworks!

    Hi,
    I tried to copy and adapt this little bit of code, but everytime I try to access to the url with the folder’s name, I get a 500 Internal Error

    I’ve checked and double checked, I’m typed I understood this right:
    RewriteRule ^foldername/(.*)$ https://site.host.fr/pagealias/$1 [P]

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Page with the same name as an actual directory’ is closed to new replies.