caramba
caramba

Reputation: 22480

htaccess make different page acting as home page

If user goes to URL

http://example.com

The server does a 302 Moved and goes to http://example.com/en/home/my-page.html

What I want is if URL is

http://example.com/en/home/my-page.html

The browser should just show http://example.com/en/

I've tried with .htaccess like so:

RewriteEngine on

RewriteCond %{THE_REQUEST} ^en/home/my-page\.html
RewriteRule ^en/ /en/home/my-page\.html [R=301,L]
RewriteRule ^index.php$ en/home/my-page\.html [L,R=301]

but it does nothing. What am I doing wrong?

Upvotes: 1

Views: 62

Answers (2)

anubhava
anubhava

Reputation: 785206

Your regex patterns are wrong.

You can use these rule in site root .htaccess:

RewriteEngine on

# externally redirect /en/home/my-page.html to /en/
RewriteCond %{THE_REQUEST} \s/+en/home/my-page\.html[?\s/]
RewriteRule ^ /en/ [R=301,L]

# internally rewrite /en/ to /en/home/my-page.html
RewriteRule ^en/?$ en/home/my-page\.html [L,NC]

Don't forget to clear your browser cache before testing this change.

Upvotes: 1

krasipenkov
krasipenkov

Reputation: 2029

This code will redirect user hitting

http://example.com/en/my-page.html

to

http://example.com/en/

and than will internally redirect thr request to index.php (you can substitute parameter with the directory where index.php is located or just remove it if it is in the main dir)

RewriteRule ^en/my-page\.html$ /en/ [L,R=301]

RewriteRule ^en/ /<dir>/index.php [L]

Upvotes: 0

Related Questions