• Ok so here is the problem I’d like to solve:

    Our website was installed inside a folder on purpose and we pointed apache to look in the right direction using a few lines in htaccess. So if someone types “website.com” it will automatically resolve “website.com/en”. So when the website is reached, it will resolve everything else accordingly “website.com/en/wp-admin”

    Now I want to have a page created for a specific event for example named “Test”, under normal circumstances to reach the said page, one would have to type: “website.com/en/Test”.. but in order to make it simple, I want to have that person type: “website.com/Test” and be automatically sent to “website.com/en/Test”.

    Please help me figure this one out!
    Thank you in advance.

Viewing 9 replies - 1 through 9 (of 9 total)
  • RewriteRule website\.com/Test$ http://website.com/en/Test/$1 [R=301,L]

    Not sure if that will work, but it may point you in the right direction.

    Thread Starter nawranj

    (@nawranj)

    Thank you for the help, but it didn’t work.. anyone has a solution for this?

    nawranj wrote:

    Thank you for the help, but it didn’t work.. anyone has a solution for this?

    Maybe you can post the contents of your .htaccess file here, so that we can get a better idea of what you’re dealing with. If it’s lengthy ( http://codex.wordpress.org/Forum_Welcome#Posting_Code ), please use pastebin and paste the link here.

    Please replace your actually url, domain, etc. with example.com.
    Example.com is set per RFC 2606 for these type of purposes.

    Thread Starter nawranj

    (@nawranj)

    Sure thing, here it is:

    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^example\.com$ [OR]
    RewriteCond %{HTTP_HOST} ^www\.example\.com$
    RewriteRule ^/?$ "http\:\/\/example\.com\/en" [R=301,L]
    
    # to protect wp-config.php
    <Files wp-config.php>
    order allow,deny
    deny from all
    </Files>
    
    # to protect the .htaccess file itself:
    <Files .htaccess>
    order deny,allow
    deny from all
    </Files>
    Thread Starter nawranj

    (@nawranj)

    Hmmmm so I just resolved the issue with a very simple line that made me laugh:

    RedirectMatch 301 ^/Festival$ http://example.com/en/Festival

    It did exactly what I wanted it to do! Case closed!

    First let me fix this a bit. The target in a RewriteRule shouldn’t have anything escaped.

    Before:
    RewriteRule ^/?$ "http\:\/\/example\.com\/en" [R=301,L]
    After:
    RewriteRule ^/?$ http://example.com/en [R=301,L]

    Also this ^/?$ is almost the same as this .* which is faster and probably better.

    So instead of:
    RewriteRule ^/?$ "http\:\/\/example\.com\/en" [R=301,L]
    use:
    RewriteRule .* http://example.com/en [R=301,L]

    See if your site still works with that. I’m just trying to clean up your current rules, before trying to help you with the other rewrite.

    Also, are you using WordPress “pretty links” Permalinks?

    Oh after thinking about it, all of that can be a bit more optimized.

    Before:

    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^example\.com$ [OR]
    RewriteCond %{HTTP_HOST} ^www\.example\.com$
    RewriteRule ^/?$ "http\:\/\/example\.com\/en" [R=301,L]

    After:

    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$
    RewriteRule .* http://example.com/en [R=301,L]

    Instead of saying example\.com or www\.example\.com it now says:
    example\.com with or without www\.

    Hmmmm so I just resolved the issue with a very simple line that made me laugh:

    RedirectMatch 301 ^/Festival$ http://example.com/en/Festival

    It did exactly what I wanted it to do! Case closed!

    Oh, just saw that. Glad it’s working. Be careful using mod_rewrite and mod_redirect together like that, you may experience unwanted side effects. I always try to stick with one or the other.

    Thread Starter nawranj

    (@nawranj)

    Wow thank you very much for taking the time to help me! It means a lot! Do you have a better suggestion? I mean right now the code is doing what I want it to, but if you feel there is a better solution to this, I am all open to suggestions!

    Edit: Ok so I just used the modified code that you suggested, and it pretty much nullified Mod_redirect, as it went back to the original example.com/en link whenever I enter example.com/Festival. Where as right now, Mod_redirect is working well with the snippet of Mod_rewrite.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Page Direction & htaccess’ is closed to new replies.