Page 1 of 1

Rewrite url

Posted: Tue Apr 16, 2013 2:19 pm
by YoussefSiblini
Hi,

I am using joomla, I want to get rid of the categories in my url, so I want:

Code: Select all

http://www.mygreatmove.com/before-you-arrive/neighbourhood
to be
http://www.mygreatmove.com/neighbourhood
I used this in the .htaccess file:

Code: Select all

RewriteEngine On
RewriteRule ^before-you-arrive(.*)$ http://mygreatmove.com/neighbourhood [R=301,L]
But this is redirecting to http://mygreatmove.com/neighbourhood and giving me a 404 error.

I want to know how to rewrite and not to redirect?

I will appreciate any help :)

Joe

Re: Rewrite url

Posted: Tue Apr 16, 2013 3:01 pm
by McInfo
The "R=301" flag in your RewriteRule means that the browser should "Redirect", or make a new request, for the rewritten URL and the server should send a status code of 301 when telling the browser to do so.

Re: Rewrite url

Posted: Tue Apr 16, 2013 3:18 pm
by YoussefSiblini
Thank you for your reply,

This is my first time using the .htaccess file, what I did now is that I got rid of the [R=301,L]:

Code: Select all

RewriteRule ^before-you-arrive(.*)$ http://mygreatmove.com/neighbourhood
But it is not doing anything now.

Re: Rewrite url

Posted: Wed Apr 17, 2013 4:00 pm
by YoussefSiblini
My latest code I ended up with is:

Code: Select all

RewriteEngine On
RewriteBase /
RewriteRule ^/neighbourhood /before-you-arrive/neighbourhood [L]
and still not making any changes.

Re: Rewrite url

Posted: Sat Apr 20, 2013 11:15 am
by McInfo
As the Apache documentation says, because the rewrite is defined in .htaccess context, "the path prefix of the directory containing the .htaccess file is stripped before matching." So try removing the first slash.

Code: Select all

RewriteRule ^neighbourhood /before-you-arrive/neighbourhood [L]
If that doesn't work (and I don't really expect it to), read the Joomla! documentation on search engine friendly URLs. Pay particular attention to where it mentions aliases. You may be able to define an alias so the rewrite is done by Joomla! instead of Apache Server.

I suspect the problem with doing an internal rewrite using the RewriteRule approach is that, while you achieve the user seeing a final REQUEST_URI of "/neighbourhood", Joomla! sees that same REQUEST_URI and not the "/before-you-arrive/neighbourhood" that it needs for its routing logic. When the RewriteRule redirects a user from "/neighbourhood", Joomla! receives the "/before-you-arrive/neighbourhood" REQUEST_URI, but the user sees the long version too.

Re: Rewrite url

Posted: Sat Apr 20, 2013 3:16 pm
by YoussefSiblini
Hi Guys thank you so much for your help,

I solved this issue, I found a helpful topic on line that helped me lots so I will copy and paste it here may be will be useful for some users who are having the same issue:

Code: Select all

(a) Create a new menu (NOT menu item)
(b) In the new menu created create a menu item for book1
(c) Edit the menu item book1 in the existing menu (e.g., Main Menu) and change the menu item to be Menu Alias and point that to the menu item created in step (b)