1

I'm trying to redirect an HTML page to a WordPress page which has no extension. The result of redirecting example.com/fa/home.html to example.com/fa/ is a 404 page not found. As you can see they're both in a sub-directory.

I've tried many approaches, whether manually or through cPanel to redirect those URLs. Note that I'm using a Nginx web server.

When I try to redirect another URL like example.com/en/home.html which is NOT in the /fa directory, it will successfully redirect. I have an .htaccess file in the root folder and one in the /fa directory. I deleted everything in the .htaccess file in the /fa directory and only left the default index page rule, but still no luck.

The .htaccess code in the root directory is:

RewriteEngine on
DirectoryIndex Portal.html

RewriteEngine On
RewriteCond %{HTTP_HOST} ^mscaspian.com$
RewriteRule (.*) http://www.mscaspian.com/$1 [R=301,L]

RewriteCond %{HTTP_REFERER} !^http://mscaspian.com/.*$      [NC]
RewriteCond %{HTTP_REFERER} !^http://mscaspian.com$      [NC]
RewriteCond %{HTTP_REFERER} !^http://www.mscaspian.com/.*$      [NC]
RewriteCond %{HTTP_REFERER} !^http://www.mscaspian.com$      [NC]
RewriteRule .*\.(jpg|jpeg|gif|png|bmp)$ http://www.mscaspian.com [R,NC]

ErrorDocument 404 /404.html 

And the code in the /fa directory is:

 DirectoryIndex index.html index.htm index.php

 <IfModule mod_rewrite.c>
 RewriteEngine On
 RewriteBase /fa/
 RewriteRule ^index\.php$ - [L]
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteRule . /fa/index.php [L]
8
  • You have to show your redirect code for us to help you
    – John Conde
    Jul 22, 2014 at 20:32
  • i added them in the question. they're like the default settings. by the way, my wordpress install folder is in a sub-directory of /fa.
    – user38723
    Jul 22, 2014 at 20:41
  • You need a 301 Redirect, not a URL Rewrite.
    – eyoung100
    Jul 22, 2014 at 20:41
  • when i do the 301 Redirect in Cpanel it writes RewriteCond %{HTTP_HOST} ^mscaspian\.com$ [OR] RewriteCond %{HTTP_HOST} ^www\.mscaspian\.com$ RewriteRule ^fa\/home\.html$ "http\:\/\/www\.mscaspian\.com\/fa\/" [R=301,L] in the root htaccess
    – user38723
    Jul 22, 2014 at 20:44
  • You state you are using Nginx, but you are using Apache .htaccess directives - how does that work?
    – MrWhite
    Jul 23, 2014 at 10:12

1 Answer 1

1

I believe this will start you off right: I don't believe the rewrite rule is necessary, when the default page for WordPress is index.php

Options +FollowSymLinks
RewriteEngine on

Redirect 301 ^/home.html http://www.mscaspian.com/fa

Update

Localizing WordPress
List of Localization Plug-Ins

I am not affiliated in any way to the list of plug-ins above, just Googled for:

localize wordpress content


Update 2
List of Common Redirects

As per your comment, you need to add a redirect rule for all pages, as a separate line, Ex:

Redirect 301 ^/about.html http://www.mscaspian.com/fa/about
Redirect 301 ^/contact.html http://www.mscaspian.com/fa/contact

As I stated earlier, since the default page is index.php. and all these pages are handled by index.php, redirecting to the "Pretty URL" is perfectly legal, only if you have the rules for Pretty Permalinks Enabled, before the redirects.

14
  • i added the the code once in root htaccess and once in /fa directory's, still getting 404 error. the directory is blocked by robots.txt so you can check the live URL.
    – user38723
    Jul 22, 2014 at 20:50
  • Because to Apache your localized version counts as a Directory, and you only need it in the root, as people typing home.html need to go to /fa. Visitors in /fa are already in the correct place. See Edit.
    – eyoung100
    Jul 22, 2014 at 20:54
  • Oh yes now it's redirecting. your edited code works just fine. i have no idea what an ^ can do in there but apparently that just changed everything. Thank you!
    – user38723
    Jul 22, 2014 at 21:03
  • the Carat(^) is a WildCard Character. Translation: Catch all URL's that end in /home.html regardless of whats in front of home.html. Your rule was incorrectly coded because you weren't catching the localized translation language in the path. Be aware with that rule, that until you localize WordPress, all visitors, regardless of language will be redirected to the Arabic language page
    – eyoung100
    Jul 22, 2014 at 21:10
  • i have 2 questions. 1st. what if i wanted to use the above rule in the root htaccess instead of the one in the /fa directory. and 2nd. i almost localized wordpress for that language but wordpress is so smart that it will know which directory it is in and if the directory's name is one of language code (like fr/fa/en) it will have different response ? sorry if i ask simple questions.
    – user38723
    Jul 22, 2014 at 21:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.