Forum Moderators: phranque

Message Too Old, No Replies

How Can I Correct Joomla Sef by htaccess?

htaccess,Joomla,Sef

         

hafezna

1:03 pm on Nov 12, 2011 (gmt 0)

10+ Year Member



Hi frinds...
My CMS is joomla with actived core sef:

I have some error in URL's
----------------------------------------------------
Error 1:
I had 4 URL's for my first page:
(with or without www)

The non-sef url1:
www.hafezna.ir/index.php

The non-sef url2:
www.hafezna.ir/home.html

The non-sef url3:
www.hafezna.ir/home

The sef url1:(It's My Favorite)
www.hafezna.ir/

------------------------------------------------------
Error 2:
I have 3 URLS for one article:

The non-sef url4:
[hafezna.ir...]

The non-sef url5:
[hafezna.ir...]

The sef ur2: (It's My Favorite)
[hafezna.ir...]
_________________________________________________________

Now,

I want redirect all non-sef urls to my firstpage (www.hafezna.ir)!

How can I do it?

I tried redirect "The non-sef url4" and "The non-sef url5" to "The sef url1"

It was successful for "The non-sef url5" (with index.php) but not for "The non-sef url4"(without index.php)


RewriteCond %{THE_REQUEST} ^\?option=(.*)\ HTTP/
RewriteRule ^index\.php$ http://www.hafezna.ir? [R=301,L]


can any body help me?

g1smd

9:01 pm on Nov 12, 2011 (gmt 0)

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



You need a much more complex rule than that: one that I have posted in the offficial Joomla forums several times this year.

Copy it to this thread if you want to discuss it further.

lucy24

9:47 pm on Nov 12, 2011 (gmt 0)

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



... and when you do, make sure all your examples are changed to www.example.com so they don't turn into auto-links. (Useful if you want to go to the site, useless if you want people to see what you actually typed.)

And :: cough, cough :: this forum's version of the <b> trick-- for those times when there's no alternative-- is to sneak a pair of empty [ b][/ b] tags (without space) into the middle of the http. Otherwise you'll just get a malformed autolink. Also works in php/bb2 forums but not bb3 ;)

hafezna

10:12 pm on Nov 12, 2011 (gmt 0)

10+ Year Member



thank for your tips about the forum ;)

I could solved it by filter some special words...



RewriteCond %{THE_REQUEST} option=com_content
RewriteRule ^(.*)$ http://hafezna.ir? [L,R=301]

RewriteCond %{THE_REQUEST} frontpage.html
RewriteRule ^(.*)$ http://hafezna.ir? [L,R=301]



It works perfect...

g1smd

10:18 pm on Nov 12, 2011 (gmt 0)

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



Target URL should have slash before question mark.

lucy24

1:53 am on Nov 13, 2011 (gmt 0)

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



It works perfect...

But, but, but, what does it do exactly? Right now you've got (after some spit & polish)

RewriteCond %{THE_REQUEST} (option=com_content|frontpage\.html)
RewriteRule .* http://hafezna.ir/? [L,R=301]


So you're pulling out certain requests, either for named pages or for some specific parameter, and sending them to the front page after stripping the query string, if any. What happens to all the other requests?

hafezna

8:56 pm on Nov 17, 2011 (gmt 0)

10+ Year Member



@lucy24

I just add a "htaccess" file in administrator directory (without this code) so it works now..I test it for several days...be sure!

phranque

10:32 am on Nov 18, 2011 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



welcome to WebmasterWorld, hafezna!

it doesn't look like your redirects will solve your home page canonicalization problem. (e.g. redirecting requests for /home or /home.html)

in addition it is rarely a good idea to implement a massive redirect to your home page.
your RewriteCond directive and the pattern in your RewriteRule should be as specific as possible.

hafezna

2:07 pm on Nov 18, 2011 (gmt 0)

10+ Year Member



Hi phranque

Thanks for the report :)

with this code I solved it:


RewriteCond %{THE_REQUEST} ^GET\ /index\.(php|html) [NC]
RewriteRule ^index\.php$ http://www.hafezna.ir/$1 [R=301,L]
Redirect 301 /index http://hafezna.ir/
Redirect 301 /home http://hafezna.ir/


Now I think I have a unique URL's per page...

phranque

2:37 pm on Nov 18, 2011 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



you shouldn't mix mod_rewrite directives (RewriteRule) with mod_alias directives (Redirect).
you should use mod_rewrite exclusively for your solution.

try these requests:
- http://example.com/home.html
- http://example.com/index.php?foo=bar

(substituting your hostname for example.com)


also you should fix whatever is generating the non-sef urls.

lucy24

2:35 am on Nov 19, 2011 (gmt 0)

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



Uh, if the RewriteRule specifically refers to .php, what's .html even doing in the Cond? If you want to redirect everything that asks for /index, simply leave off the \.php$ part of the RewriteRule.

Do you have a rule somewhere else that rewrites (not redirects) to "index.php" and/or "index.html"? If not, you don't need the condition at all.

:: idly thinking that phranque and I appear to have gotten the same StickyMail ;) ::