Forum Moderators: phranque

Message Too Old, No Replies

redirecting path in a directory to /directory/ using .htaccess

joomla duplicated links

         

sime

12:38 pm on Oct 14, 2017 (gmt 0)

5+ Year Member



If anyone knows, please help
I'm not expert
joomla 3.8.1
What code is necessary to insert in .htaccess - to solve the problem of home pages

https://www.example.com/de/home to https://www.example.com/de/
https://www.example.com/en/home to https://www.example.com/en/
https://www.example.com/it/home to https://www.example.com/it/
https://www.example.com/ru/home to https://www.example.com/ru/
https://www.example.com/uk/home to https://www.example.com/uk/

sime

[edited by: phranque at 1:05 pm (utc) on Oct 14, 2017]
[edit reason] unlinked urls [/edit]

phranque

1:04 pm on Oct 14, 2017 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



welcome to WebmasterWorld, sime! [webmasterworld.com]

what have you tried so far?

here is a thread describing a similar issue which may be helpful reading to get started:
Redirecting index.php within a directory [webmasterworld.com]

phranque

1:06 pm on Oct 14, 2017 (gmt 0)

sime

1:23 pm on Oct 14, 2017 (gmt 0)

5+ Year Member



ok.thanks ( sorry for xxx links )
so far.
I tried to insert this:
RewriteCond %{HTTP_HOST} !https://www.example.com/de/home$ [NC]
RewriteRule ^(.*)$ https://www.example.com/de/$1 [L,R=301]

but it was not good
I got this link

https://www.example.com/de/de/de/de/de/de/uk

I do not see the possibility of inserting an existing htacces file (in the forum)
just copy / paste
sime

lucy24

6:34 pm on Oct 14, 2017 (gmt 0)

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



RewriteCond %{HTTP_HOST} !https://www.example.com/de/home$ [NC]
That's not a host. The HTTP_HOST is the first element of an URL, without the protocol, leaving only the "www.example.com" part. And, since the condition here is negative, it will always match and the rule will always execute and you'll get an infinite loop.

Are you simply trying to omit the element /home from any and all URLs? If so, use the same rule that's used to strip "index.html" from directory URLs.

sime

7:20 pm on Oct 14, 2017 (gmt 0)

5+ Year Member



thanks for your reply
I'm just trying to solve the problem of duplicate links in joomla.
A very big problem was made.
My website is small and I have over 300 Hreflang Tags with Errors.
I solved some problems with duplicate links with GWT using URL Parameters.
For example :
id, start, hitcount, limitstart
I still have to solve the home and category
Now I'm trying to solve a home
sime

[edited by: sime at 7:55 pm (utc) on Oct 14, 2017]

sime

7:32 pm on Oct 14, 2017 (gmt 0)

5+ Year Member



something like this

RewriteCond %{THE_REQUEST} ^.*/home
RewriteRule ^(.*)home$ https://www.example.com/$1 [R=301,L]


sime

lucy24

8:41 pm on Oct 14, 2017 (gmt 0)

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



Yup, that can fit nicely with your existing index redirect (which you should have even if you don't actually use "index.html"). For example--don't copy-and-paste, because this is off the top of my head--
RewriteCond %{THE_REQUEST} ^/((?:[\w-]+/)*)(?:home|index\.html)
RewriteRule (?:home|index\.html)$ https://www.example.com/%1 [R=301,L]
Yes, you can do the capture within the RewriteRule and omit the RewriteCond entirely (adding an NS flag if you do use index.html, and changing %1 to $1). But since the capture is extra work for the server, and will end up being thrown away 99% of the time, I like to put it in a RewriteCond instead.

In addition to "home" and "index.html" you can now add any other element that isn't supposed to be part of your URL. The closing anchor in the pattern means you do not need to worry about URLs that just happen to contain "home", like /homeplace/ or /homework/. Conversely, the / slash in the capture means that elements like /athome/ are unaffected.

sime

9:22 pm on Oct 14, 2017 (gmt 0)

5+ Year Member



Thanks
when I insert the code (yes, I changed example.com)
no changes
I still have a page www.example.com/de/home, www.example.com/it/home ....

this is my ,htacces file
...........................................

## No directory listings
IndexIgnore *

## Can be commented out if causes errors, see notes above.
Options +FollowSymlinks
Options -Indexes

## Mod_rewrite in use.

RewriteEngine On
RewriteCond %{HTTPS} !on
# This checks to make sure the connection is not already HTTPS
RewriteRule ^/?(.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{THE_REQUEST} ^/((?:[\w-]+/)*)(?:home|index\.html)
RewriteRule (?:home|index\.html)$ https://www.example.com/%1 [R=301,L]

## Begin - Rewrite rules to block out some common exploits.
# If you experience problems on your site then comment out the operations listed
# below by adding a # to the beginning of the line.
# This attempts to block the most common type of exploit `attempts` on Joomla!
#
# Block any script trying to base64_encode data within the URL.
RewriteCond %{QUERY_STRING} base64_encode[^(]*\([^)]*\) [OR]
# Block any script that includes a <script> tag in URL.
RewriteCond %{QUERY_STRING} (<|%3C)([^s]*s)+cript.*(>|%3E) [NC,OR]
# Block any script trying to set a PHP GLOBALS variable via URL.
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
# Block any script trying to modify a _REQUEST variable via URL.
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
# Return 403 Forbidden header and show the content of the root home page
RewriteRule .* index.php [F]
#
## End - Rewrite rules to block out some common exploits.

## Begin - Custom redirects
#
# If you need to redirect some pages, or set a canonical non-www to
# www redirect (or vice versa), place that code here. Ensure those
# redirects use the correct RewriteRule syntax and the [R=301,L] flags.
#
## End - Custom redirects

##
# Uncomment the following line if your webserver's URL
# is not directly related to physical file paths.
# Update Your Joomla! Directory (just / for root).

RewriteBase /

## Begin - Joomla! core SEF Section.
#
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
#
# If the requested path and file is not /index.php and the request
# has not already been internally rewritten to the index.php script
RewriteCond %{REQUEST_URI} !^/index\.php
# and the requested path and file doesn't directly match a physical file
RewriteCond %{REQUEST_FILENAME} !-f
# and the requested path and file doesn't directly match a physical folder
RewriteCond %{REQUEST_FILENAME} !-d
# internally rewrite the request to the index.php script
RewriteRule .* index.php [L]
#
## End - Joomla! core SEF Section.

[edited by: phranque at 11:13 pm (utc) on Oct 14, 2017]
[edit reason] Unlinked URL for clarity [/edit]

lucy24

10:35 pm on Oct 14, 2017 (gmt 0)

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



Oh, yikes, some of that is in the wrong order. Among RewriteRules, it goes like this

#1 any hole-poking rules to allow access to custom 403 page, robots.txt and so on
#2 any rules with [F] flag
#3 any rules with [G] flag (if any) and also any rules with hard-coded R=404 (rare but sometimes useful)
#4a any specific redirects
#4b index-redirect (this is also where your /home redirect goes)
#4c domain-name-canonicalization redirect (rule for wrong www and/or https)
#5 internal rewrites in [L] alone

If you are using any of the standard CMS packages, this last bit--the rewrites--will probably be inside an <IfModule> envelope, and may also be surrounded by comment lines naming the specific CMS. Keep this entire package together, but make sure it is in the proper location overall.

sime

8:00 am on Oct 16, 2017 (gmt 0)

5+ Year Member



hello Lucy24
sorry for delay and I'm sorry to bother you
This is a standard joomla package - a simple protostar template.
I did not change anything.
About htaccess I do not know anything.
except that I read that when I change http to https i need to enter the code (what I did ).
in joomla is tuned on „Remove IDs from URLs“
I have only three extensions: akeeba, social and for the site map (which has in link: index-php-option-........)
if you want to look at my site's administration, I'll write you access.
if you're not in the mood, it does not matter.
I read about joomla and problems with duplicate links.
this problem lasts more than ten years! ....
And their help forum? Waste of time!
sime

lucy24

9:58 pm on Oct 16, 2017 (gmt 0)

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



The HTTPS redirect needs to go immediately before the Joomla [L] rewrites--the part that's labeled "Joomla! core SEF Section".

But wait: Is this line really from Joomla?
RewriteRule .* index.php [F] 
Once you've used the [F] flag (or anything outside the 3xx range), there is no rewrite target. So the only thing that will be shown is the 403 page--and even that can only be shown if you have previously poked a hole for it. (I don't personally speak Joomla, so I don't know how 403s are normally handled.)

sime

6:59 am on Oct 17, 2017 (gmt 0)

5+ Year Member



Hi Lucy, thank you for your reply
I just downloaded the original joomla package
yes, that code is part of the original
sime