• Resolved bsc44

    (@bsc44)


    Hi, I have a project page on my wordpress site like this, xxx.com/projects/project1 . On my server i have a subfolder called live which contains a html file also named project1.html so that file’s link is xxx.com/live/project1.html, which is what I need as people go to this link directly.

    I’m trying to use htaccess to hide the .html from the project1.html direct link, but doing so causes wordpress to redirect this link xxx.com/live/project1.html back to the project’s page link here xxx.com/projects/project1.

    I’ve tried the following two htaccess tricks with no luck. it removes the .html but then still wordpress throws me back to the project page.

    RewriteRule ^(.+).html$ /$1 [R=301,L]

    RewriteRule ^live/(.+).html$ /live/$1 [R=301,L]

    • This topic was modified 1 year, 5 months ago by bsc44.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    You are redirecting to /live/project1, but such a file does not exist. Thus WP gets control and sees “project1” (irregardless of /live/ not matching anything in WP) which matches a WP page, so that’s what is served in response.

    You need to prevent WP from getting control. You could modify the WP .htaccess directives to exclude /live/project1 requests, but then the redirect to /live/project1 will return a 404 page since such a server resource does not exist.

    I don’t see a practical solution. Why do you want to hide .html anyway? What are you trying to accomplish? Maybe there’s another solution.

    Thread Starter bsc44

    (@bsc44)

    Thanks for the reply. I should perhaps expand on the usecase for the /live/project1.html file.
    The project1.html file that is located in the /live/ subfolder is a completely seperate thing and has nothing to do with the website or wordpress in general. It’s just a seperate .html file which is used by users of the project which I created a few years, so the link still needs to remain active. When i originally linked the live project file link i always shared the link around without the .html extension as it looked cleaner, and made sure the .html was hidden from the domain url in the browser.

    Fast forward some time and now on my website i have information about that specific live project, which is a project information page if you like, located on my wordpress website under the xxx.com/projects/project1 url permalink (along iwth many other project pages), so this is why i have the need for the external xxx.com/live/project1.html link to work still, and why also there is some sort of conflict because wordpress just thinks people are trying to visit the project1 wordpress page.

    Anyways, without any automatic redirection from wordpress everything works perfectly, its only because wordpress is trying to be ‘smart’ and pull visitations of the /live/project1 link back to wordpress.

    Thread Starter bsc44

    (@bsc44)

    Okay pleased to report that this is now solved! All with a rather simple fix lol…
    I simple added the following code BEFORE the #Begin WordPress section in the .htaccess file, so that the /live/ subfolder links are dealt with BEFORE passing them down to wordpress to handle.

    RewriteEngine On
    RewriteCond %{REQUEST_URI} ^/live/project1$
    RewriteRule ^live/project1$ /live/project1.html [L]


    Woot!

    • This reply was modified 1 year, 5 months ago by bsc44.
    • This reply was modified 1 year, 5 months ago by bsc44.
Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Stop a html file in sub folder from redirecting’ is closed to new replies.