Forum Moderators: phranque

Message Too Old, No Replies

htaccess redirect question

         

Saudiqua

8:35 am on Sep 20, 2011 (gmt 0)

10+ Year Member



I'm having a problem redirecting [mydomain.com...] to [mydomain.com...]

/folder/index.html is an orphan page that I want people to access using [mydomain.com...]

Can anyone help me with this?

Thanks

Sadie

lucy24

7:53 pm on Sep 20, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



For starters: What have you tried so far, and what happens when you try it?

Saudiqua

6:51 am on Sep 21, 2011 (gmt 0)

10+ Year Member



Well I've tried using alias mod which works although it means the rest of my htaccess entries wont work. Secondly, I tried using RewriteRule with a rewritebase.

lucy24

7:04 am on Sep 21, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I meant, ahem, what exactly? Honestly, it is better to have people quietly sneering at malformed code than have them loudly swearing about nonexistent code.

If a Redirect is preventing the rest of your htaccess from working, there is something wrong with the Redirect. (Substitute any word for "Redirect" and this will probably remain true ;))

Oh, and "mydomain.com" won't work. To keep urls visible you have to use "example.com". It is hard-coded into the Forums.

Saudiqua

8:11 am on Sep 21, 2011 (gmt 0)

10+ Year Member



Okay, the .htaccess code I used was the following:

RewriteBase /var/www/html/example/app/webroot/
RewriteCond %{REQUEST_URI} ^(.*)folder/index.html$1
RewriteRule ^/seofriendly-filename(.*) [R=301,L]

The domains I want to redirect is http://www.example.com/folder/index.html to http://www.example.com/seo-friendly-filename.

g1smd

8:49 am on Sep 21, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You need a redirect (using a RewriteRule) with a preceding RewriteCond looking at THE_REQUEST. The redirect target will contain the protocol and domain name and the rule will use the [R=301,L] flags.

You need a Rewrite (using a RewriteRule) to map the friendly URL request to the internal filepath. This rule needs only the [L] flag.

As this question (or one very like it) is asked almost every day here, there's thousands of prior examples.