Forum Moderators: phranque

Message Too Old, No Replies

.htaccess Wordpress permalink redirect dilemma

Trying to redirect root to subfolder without breaking original permalinks

         

fixmonster

11:26 am on Nov 25, 2008 (gmt 0)

10+ Year Member



I am currently running Wordpress 2.6.3

I have permalinks turned on in the form of example.com/postname/

My .htaccess file by default is:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

If I go to

example.com/it

I get an italian translation of my page through the global translator plugin.

I would like if I could get example.com to show the example.com/it page by default and any attempt to go to example.com/postname would actually display example.com/it/postname.

At the same time I would like to still be able to access example.com/wp-admin for obvious reasons.

I have searched on google for hours and tried different methods, but did not end up with anything more useful than a 404 or 500 error page :) If anyone could give me some help it would be much appreciated for a mod_rewrite noob such as myself!

Thank you!

fixmonster

8:11 pm on Nov 25, 2008 (gmt 0)

10+ Year Member



Here is what I have been working with, is this getting any closer? It just tells me that /it/ is not found which I suppose is technically true, but I am trying to get it to go to the original permalink that wordpress was using.

# BEGIN WordPress

<IfModule mod_rewrite.c>

# Turn on rewrites.
RewriteEngine on

# Base
RewriteBase /

Options +FollowSymLinks

# handle domain root and skip subfolders
RewriteCond %{HTTP_HOST} example.com
RewriteCond %{REQUEST_URI} !^/it/
RewriteCond %{REQUEST_URI} \..+$
RewriteRule ^(.*)$ it/$1 [L]

# add trailing slash to subfolders (eg abc to: abc/)
RewriteCond %{HTTP_HOST} example.com
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} [^/]$
RewriteRule ^(.*)$ $1/ [L,R=301]

# handle files in subfolders
RewriteCond %{HTTP_HOST} example.com
RewriteCond %{REQUEST_URI} !^/it/
RewriteRule ^(.*)$ it/$1 [L]

</IfModule>

#<IfModule mod_rewrite.c>
#RewriteEngine On
#RewriteBase /
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
#RewriteRule . /index.php [L]
#</IfModule>
# END WordPress

jdMorgan

2:31 am on Dec 2, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Based on your description, this is all you should need:
[code]
RewriteEngine on
RewriteBase /
#
RewriteCond %{REQUEST_URI} !^/it/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /it/index.php [L]
[code]
However, if WP is using AcceptPathInfo or if it is directly examining the client's request header --as seen in mod_rewrite as the variable named %{THE_REQUEST}-- then this won't work, and you will have to externally redirect to the /it/ subdirectory to accomplish what you want. The alternative would be to set WP to use Italian by default, so that the /it/ URL-path isn't needed.

Jim

Caterham

5:25 am on Dec 13, 2008 (gmt 0)

10+ Year Member



attempt to go to example.com/postname would actually display example.com/it/postname.

WP, as a lot of scripts do, uses $_SERVER['REQUEST_URI'], which - provided as ENV to a content handler - contains the decoded URL-path value of the initial request. That means that you'll have to force an external redirect from /postname to /it/postname, because an internal rewrite from /postname to /it/postname to /index.php won't have an effect.

if WP is using AcceptPathInfo
If WP would use path_info (i.e. /foo needs to be rewritten to /index.php/foo, otherwise path_info is empty), WP won't work if php runs via a CGI wrapper.
BTW: path_info works in apache 1.3 too, it is up to the content handler whether to accept or decline requests with path_info present. That is the default behavior in apache 2.x, too. The content handler PHP accepts path_info, so there would be no need to change anything if s/o intents to use /script.php/foo or /script/foo with enabled MultiViews on apache 1.3 or later.